I have this code which retrieves data from a mysql table. I am using Python's MySQLdb module. I want EACH column's data based on the SELECT WHERE condition to be retrieved under an array. For instance, in the code below, I want all the data where location field is 'NY, US' to be retrieved under different arrays - with each array representing different columns values.
import numpy
import MySQLdb
db = MySQLdb.connect("localhost", "root", "", "test")
cursor = db.cursor()
sql = "SELECT * FROM usa_new WHERE location = 'NY, US'"
try:
cursor.execute(sql)
results = cursor.fetchall()
discresults = {}
for row in results:
id = row[0]
location = row[1]
temp_f = row[2]
pressure_mb = row[3]
wind_dir = row[4]
wind_mph = row[5]
relative_humidity = row[6]
timestamp = row[7]
except:
print "Error: unable to fecth data"
db.close()
Is there something going wrong?
discresults{}
doing there? – shakabra Nov 17 '12 at 6:51