Group by date in pandas in order to plot categorical distributions
<p>I am trying to plot data that has been binned by certain date ranges. </p>

<p>Say for example I have the following dataframe:</p>

<pre><code>dates = pd.date_range(start=pd.datetime(2013, 6, 1), periods=50, freq='D')
df = pd.DataFrame(np.random.normal(10, 3, 50), columns=['x'], index=dates)
df[:3]
            x
2013-06-01  9.819422
2013-06-02  3.659629
2013-06-03  14.862231
</code></pre>

<p>I would like to group the dates by 3 week intervals and plot the data, this gives me the average I am looking for, </p>

<pre><code>df.resample('3w', how='mean')

            x
2013-06-02  11.424715
2013-06-23  9.443888
2013-07-14  8.572851
2013-08-04  9.873879
</code></pre>

<p>But I would like to keep all of the data so that I can use boxplots in <code>seaborn</code> or include standard error using <code>matplotlib</code>. I'm completely stuck on how to achieve this without explicitly defining the ranges (which is not possible with the actual dataframes I am working with). It seems there must be a fairly straightforward way to do this in pandas so the output would be something like:</p>

<pre><code>            x           week
2013-06-01  9.819422    1
2013-06-02  3.659629    1
2013-06-03  14.862231   1
</code></pre>

<p>Where <code>week</code> is a categorical variable representing the binned data. Any thoughts would be appreciated. </p>