Reputation: 174
I want to create a simple chart with these library written below. Here is how I did:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import MySQLdb
def mysql_select_all():
conn = MySQLdb.connect(host='localhost',
user='root',
passwd='password',
db='databse')
cursor = conn.cursor()
sql = "SELECT price,size1 FROM 008_table"
cursor.execute(sql)
result = cursor.fetchall()
df = pd.DataFrame(list(sql),columns=["price","size1"])
x = df.price
y = df.size1
plt.title("Table", fontsize="24")
plt.scatter(x, y, s=100)
plt.xlabel("Size1")
plt.ylabel("Price")
plt.tick_params(axis='both',which='major',labelsize=14)
cursor.close()
print("Start")
mysql_select_all()
print("End")
I got the Value Error with this code, where should I fix this code ?
Upvotes: 0
Views: 1426
Reputation: 2302
By:
df = pd.DataFrame(list(sql),columns=["price","size1"])
did you mean to type:
df = pd.DataFrame(list(result),columns=["price","size1"])
?
Upvotes: 2