The python code below connects to my database. What I'm trying to do is iterate through a column which contains integer values, and put all of those values into a list. I will need the values in the list because I want to normalise them between a range of 0 and 1.
import MySQLdb
import sys
db = MySQLdb.connect(host="****", user="****", passwd="****", db="****", port=3306)
cursor = db.cursor()
cursor.execute("SELECT columnName FROM TABLE5")
col1 = []
numrows = int(cursor.rowcount)
for x in range(0,numrows):
row = cursor.fetchall()
col1.append(row[x])
print col1
cursor.close()
db.close()
sys.exit()
The above currently outputs the following:
[('67',)]
Traceback (most recent call last):
File "miner.py", line 12, in <module>
col1.append(row[x])
IndexError: tuple index out of range
If anyone could help that would be great!
for x in range(numrows)(which has to do with how many rows you have) then try to getrow[x]. If you have 100,000 rows with 3 columns each, do you see why this will fail by the 4th row?