【问题标题】:Show histogram in Python from dataframe从数据框中显示 Python 中的直方图
【发布时间】:2015-04-25 20:58:51
【问题描述】:

我从 csv 文件中读取数据帧。一列包含人们生日的年份(样本:1900)或“”。 如何在 Python 3 中显示列的 histogarm?

【问题讨论】:

  • 这会帮助pandas.Series.hist ?
  • 同意 John Galt,您可以在列上致电 .hist(),例如df['year'].hist() 或任何您的专栏名称
  • 我从其他列创建了该列,并且似乎是因为显示了创建下一个错误"TypeError: unorderable types: str() < float()" 当我使用新创建的列保存表并读取到新的数据文件时,.hist() 有效。
  • 现在我需要显示 2 列(年份和性别)的直方图。

标签: python-3.x pandas histogram


【解决方案1】:
d = {'gender' : Series(['M', 'F', 'F', 'F', 'M']),'year' : Series([1900, 1910, 1920, 1920, 1920])}
df = DataFrame(d)

grouped = df.groupby('gender').year
grouped.plot(kind='hist',legend=True)

【讨论】:

    猜你喜欢
    • 2017-01-02
    • 2019-12-11
    • 1970-01-01
    • 2015-04-15
    • 1970-01-01
    • 1970-01-01
    • 2013-12-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多