我试图在单个图中显示n个图表,n是美国国家编号的数字。在for循环中的单个图中的多个图表
编译器不喜欢那些2线x[j] = df['Date'] y[j] = df['Value']
=>类型错误:“NoneType”对象不与该特定错误标化的
import quandl
import pandas as pd
import matplotlib.pyplot as plt
states = pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states')
j = 0
x = []
y = []
for i in states[0][0][1:]:
df = quandl.get("FMAC/HPI_"+i, authtoken="yourtoken")
df = df.reset_index(inplace=True, drop=False)
x[j] = df['Date']
y[j] = df['Value']
j += 1
plt.plot(x[j],y[j])
plt.xlabel('Date')
plt.ylabel('Value')
plt.title('House prices')
plt.legend()
plt.show()
首先,你还没有定义'x'和'y'。所以放在某处'x = []; Y = []'。其次,你需要追加新的项目,因为在第j步中,x [j]实际上并不存在。使用x.append(...)。关于绘制数据框列表可能还有其他问题,我不确定它是否可行。 – ImportanceOfBeingErnest
感谢您的帮助,去搜索其他东西 – louisdeck