直方图上变量的标签

2024-09-29 02:21:45 发布

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

因此,我有一个数据框,其中列'Art\u Label'有一个标签,标签上有文章的分类,可能的值是'politica'、'remotes'、'elmundo'、'otros'、'policiales'、'economia'、'editorial'

这是上面的代码

data = pd.read_csv('/filename.csv', sep=',')
    data = data.drop('Unnamed: 0', axis=1)
    data.columns

Index([u'Date', u'Title', u'Encabezado', u'Art_Label', u'Media'], dtype='object')

import matplotlib.pyplot as plt
%matplotlib inline

df =  data['Art_Label']
df2 = df.value_counts()
df2.plot(kind = 'hist', xlim = (0,400))
print df2

我想用每个标签和它的频率创建一个直方图,我用´df2=df.value\u计数(),我希望能够获得直方图上每个值的标签:

这些是我从´df2=df.value\u计数()

politica      332
deportes      323
elmundo       192
otros         191
policiales    137
economia      132
editorial      96
Name: Art_Label, dtype: int64

Tags: csvdfdatavalue标签labeldf2dtype
1条回答
网友
1楼 · 发布于 2024-09-29 02:21:45

对你的问题有点困惑。你想要这个数字吗?如果是的话,我想“酒吧”是你想要的。。。你知道吗

MM = pd.Series([332, 323, 192, 191, 137, 132, 96], index=['a', 'b', 'c', 'd', 'e', 'f', 'g'])

MM.plot(kind = 'bar', xlim = (0,400))
plt.show()

enter image description here

相关问题 更多 >