Hello all,

To begin, I am working with a MySQL database using python. In the database, I am working with 3 columns: REF_ENTRY_TIME, REF_EXIT_TIME, REF_ENTRY_VALUE. My goal is to graph the net value position against time. For the time portion, both REF_ENTRY_TIME and REF_EXIT_TIME are random various times between 9:00 and 12:00. REF_ENTRY_VALUE is just a number around 100. In total I have a bout 50 columns.

The net value position is basically the sum of the REF_ENTRY_VALUE’s, but it is only between the entry and exit times. With the following code, I can calculate the net value position at the single time 9:00. However is there anyway I can run a loop to get the net value position for all the times between 9 and 12? And get the corresponding times, so I can graph the results?

I don’t have any trouble with the plotting function matplotlib, I just need help on making the two vectors.

c.execute('SELECT REF_ENTRY_VALUE FROM actual_data_table WHERE REF_ENTRY_TIME<"2010-06-29 09:00:00" and REF_EXIT_TIME>"2010-06-29 09:00:00"')
net_position_value=[sum(result2[0:i]) for i in range(1, len(result2)+1)]

Edited by Dani: Fixed formatting

7 Years
Discussion Span
Last Post by pyTony

That looks like SQL for me. Maybe you could print out result2 so we have real Python input? Or the result of

c.exectute("SELECT REF_ENTRY_VALUE FROM actual_data_table")
result = c.fetchall()
print result

if the result2 does not contain all your data

Edited by pyTony: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.