问题
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