【问题标题】:Labels of the variables on the histogram直方图上变量的标签
【发布时间】:2017-10-04 13:14:11
【问题描述】:

所以我有一个数据框,其中“Art_Label”列有一个带有文章分类的标签,可能的值是:“politica”、“deportes”、“elmundo”、“otros”、“policiales”、 '经济','社论'

这是顶部的代码

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_counts()”获得频率,我希望能够获得直方图上每个值的标签:

这些是我从 'df2 = df.value_counts()' 得到的结果

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

【问题讨论】:

    标签: python pandas histogram axis-labels


    【解决方案1】:

    对你的问题有点困惑。你要图吗?如果是这样,我认为'bar'是你想要的......

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-18
      • 1970-01-01
      • 2015-12-17
      • 1970-01-01
      相关资源
      最近更新 更多