[英]Plot from matplotlib and pandas is not working with data json file because ValueError
I tried generate a simple plot, but error here.我尝试生成一个简单的 plot,但这里出错。 My code:
我的代码:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
real_estates = pd.read_json('/Users/pablo/Desktop/project/REscraper/real_estates.json')
# print(real_estates)
plt.plot(real_estates.size, real_estates.price)
plt.show()
real_estates.json房地产.json
[
{"price": 298000.0, "size": 47.45, "rooms": 3, "price_per_square_meter": 6280.0},
{"price": 599000.0, "size": 73.0, "rooms": 2, "price_per_square_meter": 8205.0},
[...]
]
Error:错误:
ValueError: x and y must have same first dimension, but have shapes (1,) and (2500,)
Someone can help?有人可以帮忙吗?
size happens to be an attribute of a DataFrame. 大小恰好是 DataFrame 的属性。 Use a subscription or
.loc
to select the column使用订阅或
.loc
到select列
plt.plot(real_estates['size'], real_estates['price'])
# or
plt.plot(real_estates.loc[:,'size'], real_estates.loc[:,'price'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.