Hello,
This is my first time posting and just my second day using python on mysql, so please be patient with me. I should also say, I am using a linux machine. Using python I was able to make a database and a table. However, I am having difficulty getting the values from an excel and putting them into the table. The Excel document has just three columns, which are:
MATCH - this is just a four digit number
DATE - this is just a date in the 2009-06-29 format
POS - this is either just the phrase 'LONG' or 'SHORT'
However, after I do this and try to view the data, the MATCH values come out perfectly fine. The date values come out 0000-00-00 for all the dates, so that is not correct. and for the POS, I get this error:
mysql_exception s.OperationalEr ror: (1054, “Unkown column 'SHORT' in 'field list'”)
I have tried changing the variable types from VARCHAR to TEXT or DATE, but that didn't seem to work. Really any suggestions would be greatly appreciated.
The Code I am using is:
This is my first time posting and just my second day using python on mysql, so please be patient with me. I should also say, I am using a linux machine. Using python I was able to make a database and a table. However, I am having difficulty getting the values from an excel and putting them into the table. The Excel document has just three columns, which are:
MATCH - this is just a four digit number
DATE - this is just a date in the 2009-06-29 format
POS - this is either just the phrase 'LONG' or 'SHORT'
However, after I do this and try to view the data, the MATCH values come out perfectly fine. The date values come out 0000-00-00 for all the dates, so that is not correct. and for the POS, I get this error:
mysql_exception s.OperationalEr ror: (1054, “Unkown column 'SHORT' in 'field list'”)
I have tried changing the variable types from VARCHAR to TEXT or DATE, but that didn't seem to work. Really any suggestions would be greatly appreciated.
The Code I am using is:
Code:
from xlrd import open_workbook, cellname 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 (MATCH_ID VARCHAR(35) NOT NULL,DATETIME VARCHAR(35) NOT NULL,POS_TYPE VARCHAR(35) NOT NULL)') file_to_import='actualdata.xls' column_count=5 book=open_workbook(file_to_import) sheet=book.sheet_by_index(0) conn=mysql.connect(db_info) cursor=conn.cursor() for row_index in range(sheet.nrows): row_num=row_index MATCH_ID=sheet.cell(row_index,0).value DATETIME=sheet.cell(row_index,1).value POS_TYPE=sheet.cell(row_index,2).value cursor.execute('INSERT INTO actual_data_table(MATCH_ID, DATETIME, POS_TYPE) VALUES (%s, %s, %s)'%(MATCH_ID, DATETIME, POS_TYPE)) (MATCH_ID,DATETIME,POS_TYPE) cursor.close() conn.commit() conn.close()
Comment