在python中,通过x轴上的一列打印多个列计数

2024-03-29 07:38:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个数据框,其中有5列对不同主题的评论。我想通过一个目标变量团队绘制所有此类列的计数,这样我就可以一次绘制所有可用的图

数据帧如下所示:

Function             Accountability   Reward    Pay    Others
Services             Abc               Abc      Abc    Abc
Manufacturing .      NA                NA       NA     NA
Digital Technology   DEF               DEF      DEF   DEF
Services             Abc               Abc      Abc    Abc
Manufacturing .      NA                NA       NA     NA
Digital Technology   DEF               DEF      DEF   DEF

现在有2条关于问责制下的服务的评论,等等。因此,我想在一个代码中创建多个绘图,显示按函数列出的所有注释的计数。我不想有一个条形图显示一切。我想要不同的条形图,分别按函数显示每个注释列的计数


Tags: 数据函数目标主题def评论绘制团队
1条回答
网友
1楼 · 发布于 2024-03-29 07:38:53

这就是你要找的吗

import pandas as pd 
import matplotlib.pyplot as plt 
plt.rcParams['figure.figsize'] = (15,5)

# Your table has been read to 'df' 

df1 = df.drop('Function', axis=1)

plt.subplot(1,3,1)
df1[df.Function == 'Services'].count().plot.bar()
plt.title('Services')

plt.subplot(1,3,2)
df1[df.Function == 'Digital Technology'].count().plot.bar()
plt.title('Digital')

plt.subplot(1,3,3)
df1[df.Function == 'Manufacturing.'].count().plot.bar()
plt.title('Manufacturing')

Plot

相关问题 更多 >