2016-01-23 68 views
0

我卡住了一個熊貓DataFrame boxplot,並找不到任何答案來解決我的問題。熊貓Dataframe Boxplot:組一列(無子圖)

我的數據框看起來是這樣的:

subset.head() 

    c_el_spot c_el_tr_neg_cap c_el_tr_neg_wrk c_el_tr_pos_cap 
1  25.12   20.7075    -0.1    0 
2  25.12   20.7075    -0.1    0 
3  25.12   20.7075    0.0    0 
4  23.64   20.7075    0.0    0 

    c_el_tr_pos_wrk year 
0    0 2012 
1    0 2012 
2    0 2012 
3    0 2012 
4    0 2012 

subset.tail() 

     c_el_spot c_el_tr_neg_cap c_el_tr_neg_wrk c_el_tr_pos_cap 
105212  28.02    6.75    0    0 
105213  28.02    6.75    0    0 
105214  28.02    6.75    0    0 
105215  28.02    6.75    0    0 

     c_el_tr_pos_wrk year 
105211    0 2014 
105212    0 2014 
105213    0 2014 
105214    0 2014 
105215    0 2014 

而且隨着我的繪製代碼

subset.boxplot(column=['c_el_spot', 'c_el_tr_neg_cap', 'c_el_tr_neg_wrk', 
         'c_el_tr_pos_cap', 'c_el_tr_pos_wrk'], by=['year']) 

提供了一個數字,每列中的一個插曲:

enter image description here

我的問題是如下:我怎樣才能得到一列與列(變量)按列(2012年彼此相鄰的5列,......)分組?

在此先感謝!

回答

1

可以使用seaborn,這裏有一個例子:

import pandas as pd 
import numpy as np 
import seaborn 

df = pd.DataFrame(np.random.randn(1000, 4), columns=list("ABCD")) 
df["Y"] = np.random.randint(0, 4, 1000) 
df2 = pd.melt(df, id_vars="Y") 
df2.sort_values(["Y", "variable"], inplace=True) 
seaborn.boxplot(x="Y", y="value", hue="variable", data=df2) 

輸出爲:

enter image description here

+0

謝謝!熊貓有這樣的功能也會很酷;) –