【问题标题】:How to make bar charts for muultiple groups?如何为多个组制作条形图?
【发布时间】:2021-12-13 11:53:00
【问题描述】:

拥有两个类别的多组统计数据的数据框,例如:

player   position   Points     target_class
lebron    sf          23             1
Magic     pg          22             0

如何制作每个位置的平均点数(其中 5 个)的条形图,但要为每个类拆分。所以在 pandas 中并排绘制。

【问题讨论】:

  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: pandas dataframe matplotlib seaborn


【解决方案1】:

如果没有更多信息,很难知道您的期望。像这样使用sns.barplot 应该会让你接近我认为你想要的。

import seaborn as sns
import numpy as np

ax = sns.barplot(
    data=df,
    x="position",
    y="Points",
    hue="target_class",
    estimator=np.mean,
)

【讨论】:

    猜你喜欢
    • 2022-01-10
    • 1970-01-01
    • 2023-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-23
    • 1970-01-01
    相关资源
    最近更新 更多