如何使用seaborn为每个百分位数绘制通过pandas.DataFrame.describe
计算的百分位数?
目前,我需要遍历每一个。相反,我想要一个包含所有百分位数的图表。https://seaborn.pydata.org/generated/seaborn.lineplot.html有一些带有色相和样式的漂亮示例,但是我目前想知道如何正确地重塑数据框以能够使用此方法。
import pandas as pd
%pylab inline
df = pd.DataFrame({'dt':['2020-01-01', '2020-01-02', '2020-01-03', '2020-01-03'], 'bar':[1,2,3, 4], 'baz':[3,4,5, 6]})
df['dt'] = pd.to_datetime(df['dt'])
display(df)
df = df.groupby(['dt']).describe()
df = df.reset_index()
df = df.set_index(['dt'], drop=False)
display(df)
import seaborn as sns; sns.set()
# iterate for each column (bar, baz)
df_plot = df[['dt']].copy()
# iterate for each percentile
df_plot['metric'] = df['bar']['25%']
sns.lineplot(x='dt', y='metric', data=df_plot)
plt.show()
df_plot['metric'] = df['bar']['50%']
sns.lineplot(x='dt', y='metric', data=df_plot)
plt.show()
df_plot['metric'] = df['bar']['75%']
sns.lineplot(x='dt', y='metric', data=df_plot)
plt.show()