1

I am doing a groupby using pd.timegrouper on a time series dataset. When I am plotting a boxplot on this groupby object,it has subplots. I dont want to divide the plot area into subplots. I tried using the parameter subplots=False,but its throwing an error saying KEY ERROR "value".
This is the plot i am getting with subplots.
enter image description here

the code:

df['timestamp1'] = df['timestamp'].values.astype('datetime64[s]')
df=df.groupby(pd.TimeGrouper(key="timestamp1",freq="3H"),group_keys=True,as_index=True)
df.boxplot(column="value",subplots=True)

The dataframe object i am using is:
enter image description here

I want to plot all the box plots in the same area without dividing it into subplots Thanks a lot in advance.

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • 1
    You are getting subplots because you are plotting with the groupby object and not a dataframe. Every group is being plotted. `df` is no longer a dataframe. You need to perform some aggregation/transformation/apply on your groupby object and then plot. – Ted Petrou Jun 21 '17 at 13:48

1 Answers1

0

This might actually be a bug. You can get the desired outcome by selecting only the timestamp1 and value columns, therefore eliminating the need to use the column parameter.

df[['timestamp1', 'value']].groupby(pd.TimeGrouper('3H', key='timestamp1'))\
                           .boxplot(subplots=False)

I went ahead and submitted an issue for this on github.

Ted Petrou
  • 59,042
  • 19
  • 131
  • 136