Reputation: 38
How does my output show real column headers instead of auto increment numbers.
mydb = mysql.connector.connect(
host="***************",
user="****",
password="****")
mycursor = mydb.cursor()
query = "select * from odk_prod.individual_report_core where PROCESSED_BY_MIRTH = 0 "
mycursor.execute(query)
myresult = mycursor.fetchall()
df = pd.DataFrame(myresult)
print(df)
Upvotes: 0
Views: 212
Reputation: 1669
You need to create the cursor so it can return the dictionary object instead:
mycursor = mydb.cursor(dictionary=True)
Upvotes: 1
Reputation: 34086
Create a list of all columns which you want df
to have. Example:
cols = ['A', 'B', 'C', 'D']
Then do:
df.columns = cols
Upvotes: 1
Reputation: 117771
You can pass the column names explicitly:
df = pd.DataFrame(cursor.fetchall(), columns=[d[0] for d in cursor.description])
Upvotes: 1