鉴于以下数据框:
import pandas as pd
df = pd.read_json('{"genre":{"0":"Drama","1":"Comedy","2":"Action","3":"Thriller"},"count":{"0":1603,"1":1200,"2":503,"3":492}}')
是否有大熊猫单线/快速生成直方图,其中条形基于“计数”列,x轴标签是“类型”列?
答案 0 :(得分:7)
是的,您可以选择要与x
和y
关键字参数一起使用的列。您还可以使用kind='bar'
选择所需的绘图类型,在本例中为hist。
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_json('{"genre":{"0":"Drama","1":"Comedy","2":"Action","3":"Thriller"},"count":{"0":1603,"1":1200,"2":503,"3":492}}')
df.plot(x='genre', y='count', kind='bar', legend=False)
plt.show()
请注意,我还使用legend=False
删除了图例,如果您愿意,可以将其保留。