Multiple boxes from Pandas dataframe

I am trying to build a panel with several boxes of data in a pandas dataframe. The dataframe columns look like this:

data.columns Index([u'SiteId', u'obs1', u'obs2', u'obs3', u'obs4', u'obs5', u'obs6', u'date', u'area'] 

I want to create a panel of 9 different graphs (since there are 9 different geographical areas), each of which has 12 boxes for each month of the year. The following is an example with the snippet used to create the chart:

 df = data.ix[:, ['obs1','date', 'area']] df = df.set_index('date') colm = ['LOCATION 1'] for area in areas: df2 = df.loc[(df.area== area)] df2.boxplot(column=colm, by=df2.index.month, showmeans=True) 

the code above leads to a single indicator (with squares corresponding to each month in the figure), but I want to create 9 such graphs, each of which corresponds to a certain area as subheadings in the same section. In other words, I want to first group the data by region, then by month of the year, and then build the result as boxplot. Any thoughts on how I can get the desired stories? Any help is appreciated.

Also, how can I get rid of "Boxplot grouped by [1 1 1 ... 12 12 12]" and "1,1,1,1,1,1,1,1,1,1,1 .... .. "and at the top and bottom of the plot?

I cannot send images, because stackoverflow rules do not allow me. Thanks.

+5
source share
1 answer

Does it do what you want?

 fig, axs = plt.subplots(len(areas), 1, figsize=(5,45)) for ax,area in zip(axs,areas): df2 = df.loc[(df.area==area)] df2.boxplot(column=['obs1'], by=df2.index.month, showmeans=True, ax=ax) 
+1
source

Source: https://habr.com/ru/post/1232081/


All Articles