简体   繁体   English

Plot 来自 matplotlib 和 pandas 无法处理数据 Z466DEEC76ECDF5FCA6D38571F6324 因为 ValueError 文件

[英]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使用订阅.locselect

plt.plot(real_estates['size'], real_estates['price'])
# or
plt.plot(real_estates.loc[:,'size'], real_estates.loc[:,'price'])

Indexing and selecting data 索引和选择数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM