Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的数据框如下:
month category hours 1, A, 5 1, B, 8 1, C, 2 2, A, 4 2, B, 9 2, C, 5 ... 12, A, 10 12, B, 2 12, C, 4
我想使用 Python pandas 插件绘制直方图,其中 y 轴是某个月份中所有类别的所有小时数的总和,x 轴是月份。
我怎样才能做到这一点?
使用pandas.DataFrame.groupby然后plot:
pandas.DataFrame.groupby
plot
df.groupby('month')['hours'].sum().plot(kind='bar')
输出: