我想为以下数据制作子图。我平均并分组在一起。 我想按国家对x轴资源和y轴平均值进行子统计。
country resource average
india water 76
india soil 45
india tree 60
US water 45
US soil 70
US tree 85
Germany water 76
Germany soil 65
Germany water 56
Grouped = df.groupby(['country','resource'])['TTR in minutes'].agg({'average': 'mean'}).reset_index()
我尝试过,但无法在子图中绘制
最佳答案
g = df.groupby('country')
fig, axes = plt.subplots(g.ngroups, sharex=True, figsize=(8, 6))
for i, (country, d) in enumerate(g):
ax = d.plot.bar(x='resource', y='average', ax=axes[i], title=country)
ax.legend().remove()
fig.tight_layout()
关于python - python pandas 中按组分组的子图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49306221/