我想创建一个简单的图表,下面是这些库。我是这样做的:
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")
我使用此代码获得了值错误,我应该在哪里修复此代码?
答案 0 :(得分:2)
人:
df = pd.DataFrame(list(sql),columns=["price","size1"])
你打算输入:
df = pd.DataFrame(list(result),columns=["price","size1"])