【问题标题】:Is it possible to convert the same to seaborn?是否可以将其转换为seaborn?
【发布时间】:2020-11-24 20:31:18
【问题描述】:
 group = (df.groupby(['Attrition'])
   ['Department'].value_counts(normalize=True)
   .unstack('Attrition'))
print(group)

group.plot.bar(figsize=(20,5));

我们可以将其转换为 seaborn 吗?

【问题讨论】:

    标签: pandas matplotlib data-visualization seaborn


    【解决方案1】:

    一种方法是不在 Seaborn 中重做,而是将 matplotlib 的样式更改为使用带有 sns.set 的 Seaborn 样式。

    group = (df.groupby(['Attrition'])
       ['Department'].value_counts(normalize=True)
       .unstack('Attrition'))
    print(group)
    
    sns.set()
    group.plot.bar(figsize=(20,5));
    

    【讨论】:

      【解决方案2】:

      如果没有您的(样本)数据,我将不得不在这里黑暗中画画,但您可以尝试:

      group = (df.groupby(['Attrition'])
               ['Department'].value_counts(normalize=True)
               .reset_index(name='counts')
              )
      
      sns.barplot(data=group, x='Department', y='counts', hue='Attrition')
      

      【讨论】:

      • 谢谢,@Quang。这是我一直在寻找的。再次感谢。 :)
      猜你喜欢
      • 1970-01-01
      • 2018-11-21
      • 2010-09-28
      • 1970-01-01
      • 2021-10-28
      • 2021-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多