在python中绘制预先聚合的数据 [英] Plotting pre aggregated data in python
问题描述
我有一个预先汇总的元组列表:
I have a list of pre aggregated tuples:
[{'target_y_n': 0, 'value': 0.5, 'count':1000},{'target_y_n': 1, 'value': 1, 'count':10000}, ...]
我如何可视化分布( https:/ /seaborn.pydata.org/generation/seaborn.distplot.html ),也可以获取频率图,而无需将汇总表示重新扩展为每个值的 k
副本,但仍会尽可能重用现有工具,例如 distplot,countplot
?
How can I visualize the distributions (https://seaborn.pydata.org/generated/seaborn.distplot.html) or get frequency plots without re-expanding the aggregated representation to k
copies of each value, but still re-using as much as possible from existing tools like distplot, countplot
?
在R http://www.amitsharma.in/post/cumulative-distribution-plots-for-frequency-data-in-r/ 看起来确实很有希望
In R http://www.amitsharma.in/post/cumulative-distribution-plots-for-frequency-data-in-r/ looks really promising
推荐答案
基于R源,这可能是python中的答案
Based on the R source this is a possible answer in 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')
这篇关于在python中绘制预先聚合的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!