Plotting pre aggregated data in python

一笑奈何 提交于 2019-12-11 15:14:41

问题


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}, ...]

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?

edit

In R http://www.amitsharma.in/post/cumulative-distribution-plots-for-frequency-data-in-r/ looks really promising


回答1:


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')


来源:https://stackoverflow.com/questions/55585552/plotting-pre-aggregated-data-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!