簡體   English   中英

如何使用 groubby 使用 matplotlib 繪制數據

[英]how to plot data using matplotlib using groubby

如何使用groupby繪制分組數據直到現在我能夠使用 group by 顯示數據但是當我嘗試繪制結果時,它的顯示與 groupby 結果不同。

顯示結果

df.groupby("event_type").aggregate('sum').to_dict()

{'number_person': {'meeting': 130,   'music concert': 99929,   'go out ': 1542,   'playing football': 53256,   'staying at home': 17312}}

陰謀

df.groupby('event_type')['number_person'].nunique().plot(kind='bar')
plt.show()

在此處輸入圖片說明

如您所見,繪圖結果與字典結果不匹配

咱們試試吧:

df.groupby("event_type").aggregate('sum').plot.bar(figsize=(10,6))

或者您可以創建一個軸實例並繪制:

fig, ax = plt.subplots(figsize=(10,6))
df.groupby("event_type").aggregate('sum').plot.bar(ax=ax)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM