【问题标题】:Plotting pre aggregated data in python在 python 中绘制预聚合数据
【发布时间】:2019-04-09 05:19:25
【问题描述】:

我有一个预聚合元组列表:

[{'target_y_n': 0, 'value': 0.5, 'count':1000},{'target_y_n': 1, 'value': 1, 'count':10000}, ...]

如何在不将聚合表示重新扩展到每个值的 k 副本的情况下可视化分布 (https://seaborn.pydata.org/generated/seaborn.distplot.html) 或获取频率图,但仍尽可能从现有工具(如 distplot, countplot)中重复使用?

编辑

在 R 中 http://www.amitsharma.in/post/cumulative-distribution-plots-for-frequency-data-in-r/ 看起来很有希望

【问题讨论】:

    标签: python plot seaborn distribution


    【解决方案1】:

    基于 R 源代码,这是 python 中可能的答案

    df = pd.DataFrame([{'target_y_n': 0, 'value': 0.5, 'count':1000}, {'target_y_n': 0, 'value': 0.4, 'count':100},{'target_y_n': 1, 'value': 1, 'count':10000}, {'target_y_n': 1, 'value': 2, 'count':1000}])
    df = df.sort_values(['target_y_n', 'value'])
    display(df)
    
    df['count_cum'] = df.groupby(['target_y_n'])['count'].cumsum()
    display(df)
    
    sns.lineplot(x='value',y='count_cum', drawstyle='steps-pre', data= df, hue='target_y_n')
    

    【讨论】:

      猜你喜欢
      • 2015-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-02
      • 2020-03-01
      • 2016-12-17
      相关资源
      最近更新 更多