Pandas 从具有多索引列的数据框创建箱线图

Pandas 从具有多索引列的数据框创建箱线图,pandas,boxplot,multi-index,Pandas,Boxplot,Multi Index,我有多索引列的数据帧(alphas、receiver、run) 我有10次运行、多个Alpha和2个接收器 我想创建包含两个框(每个接收器一个框-rec1,rec2)的箱线图,用于10次运行中的每个alpha值 大概是这样的: repetitions=vectors\u toPlot.repetition.unique() alphas=[0.02,0.03]#这是一个示例,最终版本将有更多值 接收器=[“rec1”、“rec2”] index=pd.MultiIndex.from_产品(i

我有多索引列的数据帧(alphas、receiver、run)

我有10次运行、多个Alpha和2个接收器

我想创建包含两个框(每个接收器一个框-rec1,rec2)的箱线图,用于10次运行中的每个alpha值

大概是这样的:


repetitions=vectors\u toPlot.repetition.unique()
alphas=[0.02,0.03]#这是一个示例,最终版本将有更多值
接收器=[“rec1”、“rec2”]
index=pd.MultiIndex.from_产品(iterables,name=['alphas','receiver','run'])
multiDf=pd.DataFrame(列=索引)
#用值填充它
打印(multiDf.head())
阿尔法0.02\
接收器rec1
运行0.01.02.03.04.0
0         11744000.0  11744000.0  11744000.0  11744000.0  11744000.0   
1         11744000.0  11744000.0  11744000.0  11744000.0  11744000.0   
2         12331200.0  12331200.0  12331200.0  12331200.0  12331200.0   
3         12624800.0  12624800.0  12624800.0  12624800.0  12624800.0   
4         12331200.0  12331200.0  12331200.0  12331200.0  12331200.0   
我尝试了
df.boxplot()
的各种组合,通过和
,但我无法理解它。

您可能需要:

输出


这也适用于violinplot。
# set up the index
alphas = [0.02, 0.03] # this is example, final version will have more values
receivers = ["rec1", "rec2"]
runs = np.arange(4)
index = pd.MultiIndex.from_product([alphas, receivers, runs], names=['alphas', 'receiver', 'run'])

# toy data
np.random.seed(1)
df = pd.DataFrame(np.random.uniform(0,1, (10,len(index))), columns=index)

# plot
sns.boxplot(x='alphas', y=0, hue='receiver', data=df.unstack().reset_index())