First of all, thank you for taking the time to read my question. With the following code, what I have done is make a database in MySQL and created a table using python. I then imported an excel document with three columns. These three colums are:
1. POS_TYPE which is either the word 'LONG' or 'SHORT.
2. REF_ENTRY_TIME which is a time int eh YYYY-MM-DD 00:00:00 format
3. REF_ENTRY_VALUE which is just a number between 600 and 700
right now at the end of my code if i type in 'real result' I get about 25 REF_ENTRY_VALUE's. From here I have a two part question.
First, with these values, is there anyway I can multiply the REF_ENTRY_VALUE by (-1) if the corresponding POS_TYPE is 'SHORT' and leave it alone if it is 'LONG'? The important thing for me would be keeping the order.
Second, for 'real result', I currently get 25 values. Is there anyway I can run a loop to aggregate these numbers. What I mean by that is, for example turn a set of numbers like (1,2,3,4,5,6,7,8,9,10) into (1,1+2,1+2+3,1+2+3+4,1+2+3+4+5....) I plan on working with a lot of values so doing by hand would not be practical.
REALLY ANY HELP WILL BE GREATLY APPRECIATED!!
from xlrd import open_workbook, cellname
import datetime, xlrd
import MySQLdb as mysql
db=mysql.connect(DB_INFO)
c=db.cursor()
c.execute('CREATE DATABASE actual_data')
db=mysql.connect(DB_INFO)
c=db.cursor()
c.execute('CREATE TABLE actual_data_table (,POS_TYPE VARCHAR(35) NOT NULL, REF_ENTRY_VALUE VARCHAR(35) NOT NULL, ,REF_ENTRY_TIME DATETIME NOT NULL)
file_to_import='actual_daily_report_2010-06-29.xls'
column_count=43
book=open_workbook(file_to_import)
sheet=book.sheet_by_index(0)
db=mysql.connect(DB_INFO)
c=db.cursor()
for row_index in range(sheet.nrows):
row_num=row_index
POS_TYPE=sheet.cell(row_index,0).value
REF_ENTRY_VALUE=sheet.cell(row_index,1).value
REF_ENTRY_TIME=sheet.cell(row_index,2).value
REF_ENTRY_TIME_as_datetime=datetime.datetime(*xlrd.xldate_as_tuple(REF_ENTRY_TIME, book.datemode))
c.execute('insert into actual_data_table values ("%s","%s","%s")’ % (POS_TYPE,REF_ENTRY_VALUE,REF_ENTRY_TIME_as_datetime))
db=mysql.connect(DB_INFO)
c=db.cursor()
c.execute('SELECT REF_ENTRY_VALUE FROM actual_data_table WHERE REF_ENTRY_TIME>"2010-06-29 09:45:00" and REF_ENTRY_TIME<"2010-06-29 12:00:00"')
result1=c.fetchall()
for item in result1:
...print float(item[0])
[float(item[0]) for item in result1]=real_result