【问题标题】:pandas frequency table histograms distribution fittingpandas 频率表直方图分布拟合
【发布时间】:2015-12-15 20:39:34
【问题描述】:

我有一个频率表df 像这样的大频率

...         freq
(20, 21]    5235211
(21, 22]    5232121
(22, 23]    1241228
(23, 24]    9412034
(24, 25]    2356336
(25, 26]    3782721
(26, 27]    9978733
...

bin 是索引。

我想用here 等分布拟合绘制漂亮的直方图。但 该函数(sns.distplot)以及其他分布图(df.plot.kdedf.plot.histdf.plot.density 等)仅采用一维列表或Series

如何改用频率表来获得相同的结果?将df 扁平化为一维数组是不切实际的,因为它的尺寸很大。

【问题讨论】:

    标签: python pandas matplotlib


    【解决方案1】:

    找到了,plt.hist 有一个名为weights 的参数,我可以向它传递一个权重数组。只需将freq 列传递给plt.hist 就可以了。与 Seaborn:

    sns.distplot(df.index, hist_kws={"weights":list(df.freq)})
    

    【讨论】:

      猜你喜欢
      • 2017-12-23
      • 1970-01-01
      • 2017-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-15
      相关资源
      最近更新 更多