title: Matplotlib Bar Graph Error - TypeError: only size-1 arrays can be converted to Python scalars
body: <p>Suppose I have the following DataFrame:</p>
  <pre><code>import pandas as pd
  import matplotlib.pyplot as plt
  from datetime import datetime as dt
  
  df = pd.DataFrame(
      [
          ['2008-02-19', 10],
          ['2008-03-01', 15],
          ['2009-02-05', 20],
          ['2009-05-10', 40],
          ['2010-10-10', 25],
          ['2010-11-15', 5]
      ],
      columns = ['Date', 'DollarTotal']
  )
  df
  </code></pre>
  <p><a href="https://i.stack.imgur.com/k5LoJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k5LoJ.png" alt="df" /></a></p>
  <p>I want to plot the total summed by year so I perform the following transformations:</p>
  <pre><code>df['Date'] = pd.to_datetime(df['Date'])
  df_Year = df.groupby(df['Date'].dt.year)
  df_Year = df_Year.sum('DollarTotal')
  df_Year
  </code></pre>
  <p><a href="https://i.stack.imgur.com/GGhEh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GGhEh.png" alt="df_Year" /></a></p>
  <p>The following code in matplotlib creates the chart below:</p>
  <pre><code>fig,ax = plt.subplots()
  ax.plot(df_Year.index, df_Year.values)
  ax.set_xlabel(&quot;OrderYear&quot;)
  ax.set_ylabel(&quot;$ Total&quot;)
  ax.set_title(&quot;Annual Purchase Amount&quot;)
  plt.xticks([x for x in df_Year.index], rotation=0)
  plt.show()
  </code></pre>
  <p><a href="https://i.stack.imgur.com/DuYJ3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DuYJ3.png" alt="plot" /></a></p>
  <p>The <strong>problem</strong> occurs when I want to create a <strong>bar graph</strong> using the same DataFrame. By changing the code above from <code>ax.plot</code> to <code>ax.bar</code>, I get the following error:</p>
  <p><a href="https://i.stack.imgur.com/E6zWc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E6zWc.png" alt="error" /></a></p>
  <p>I've never come across this error before when plotting in matplotlib. What have I done wrong?</p>
  <p><em><strong>Please see the answer below by dm2 which solves this problem.</strong></em></p>
  <hr />
  <p><strong>Edit:</strong></p>
  <p>I just figured out why I never had this problem in the past. It has to do with how I summed the <code>groupby</code>. If I replace <code>df_Year = df_Year.sum('DollarTotal')</code> with <code>df_Year = df_Year['DollarTotal'].sum()</code> then this problem does not occur.</p>
  <pre><code>df = pd.DataFrame(
      [
          ['2008-02-19', 10],
          ['2008-03-01', 15],
          ['2009-02-05', 20],
          ['2009-05-10', 40],
          ['2010-10-10', 25],
          ['2010-11-15', 5]
      ],
      columns = ['Date', 'DollarTotal']
  )
  df['Date'] = pd.to_datetime(df['Date'])
  df_Year = df.groupby(df['Date'].dt.year)
  df_Year = df_Year['DollarTotal'].sum()
  df_Year
  </code></pre>
  <p><a href="https://i.stack.imgur.com/qOuf1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qOuf1.png" alt="df_sum" /></a></p>
  <pre><code>fig,ax = plt.subplots()
  ax.bar(df_Year.index, df_Year.values)
  ax.set_xlabel(&quot;OrderYear&quot;)
  ax.set_ylabel(&quot;$ Total&quot;)
  ax.set_title(&quot;Annual Purchase Amount&quot;)
  plt.xticks([x for x in df_Year.index], rotation=0)
  plt.show()
  </code></pre>
  <p><a href="https://i.stack.imgur.com/RBqXZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RBqXZ.png" alt="enter image description here" /></a></p>