在 python 中绘制预聚合数据
Plotting pre aggregated data in python
我有一个预聚合元组列表:
[{'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/ 看起来很有前途
根据 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')
我有一个预聚合元组列表:
[{'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/ 看起来很有前途
根据 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')