title: Side-by-side boxplot of multiple columns of a pandas DataFrame
body: <p>One year of sample data:</p>
  
  <pre><code>import pandas as pd
  import numpy.random as rnd
  import seaborn as sns
  n = 365
  df = pd.DataFrame(data = {"A":rnd.randn(n), "B":rnd.randn(n)+1},
                    index=pd.date_range(start="2017-01-01", periods=n, freq="D"))
  </code></pre>
  
  <p>I want to boxplot these data side-by-side grouped by the month (i.e., two boxes per month, one for <code>A</code> and one for <code>B</code>).</p>
  
  <p>For a single column <code>sns.boxplot(df.index.month, df["A"])</code> works fine. However, <code>sns.boxplot(df.index.month, df[["A", "B"]])</code> throws an error (<code>ValueError: cannot copy sequence with size 2 to array axis with dimension 365</code>). Melting the data by the index (<code>pd.melt(df, id_vars=df.index, value_vars=["A", "B"], var_name="column")</code>) in order to use seaborn's <code>hue</code> property as a workaround doesn't work either (<code>TypeError: unhashable type: 'DatetimeIndex'</code>). </p>
  
  <p>(A solution doesn't necessarily need to use seaborn, if it is easier using plain matplotlib.)</p>
  
  <h1>Edit</h1>
  
  <p>I found a workaround that basically produces what I want. However, it becomes somewhat awkward to work with once the DataFrame includes more variables than I want to plot. So if there is a more elegant/direct way to do it, please share!</p>
  
  <pre><code>df_stacked = df.stack().reset_index()
  df_stacked.columns = ["date", "vars", "vals"]
  df_stacked.index = df_stacked["date"]
  sns.boxplot(x=df_stacked.index.month, y="vals", hue="vars", data=df_stacked)
  </code></pre>
  
  <p>Produces:
  <a href="https://i.stack.imgur.com/5xnx9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5xnx9.png" alt="Side-by-side boxplot of A and B, grouped by month."></a></p>