Using matplotlib boxplot with groupby

℡╲_俬逩灬. 提交于 2019-12-24 04:33:09

问题


I have what superficially appears to be a simple question, but I cannot find the answer. I have a feature in my df for which I would like to use groupby on two different categories. Here's my metacode:

df = pd.DataFrame(np.random.rand(100,2), columns=['Col1', 'Col2'] )
# Assume each series below repeats.  
df['X'] = pd.Series(['A','B','A','B',...,'A','B','A','B'])
df['Y'] = pd.Series(['X','Y','X','Y',...,'X','Y','X','Y'])

How can I use groupby to create 4 box plotsfor a particular feature in the df? (Eg, keys {'A','X'},{'B','X'},{'A','Y'},{'B','Y'}) for the each data series? I can do the following:

df['Col1'].groupby([df.X,df.Y]).describe()

...what's the analogy for box plot?

来源:https://stackoverflow.com/questions/31976640/using-matplotlib-boxplot-with-groupby

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