0

I'm trying to create an area chart with a pandas DataFrame.

Here's what I get when I plotted the data as it was imported.

debt[['Record_Date', 'Debt_Held_by_the_Public']].plot(kind='area')

First Plot

I converted the "Record_Date" field to a datetime field, and I get nothing when trying to plot it.

debt['Record_Date'] = pd.to_datetime(debt['Record_Date'])
debt[['Record_Date', 'Debt_Held_by_the_Public']].plot(kind='area')

Second Plot

What am I doing wrong? The Record_Date was listed as an object originally. Once I converted that field, it shows up as datetime64.

This message appears when trying to make the second plot.

TypeError: The DTypes <class 'numpy.dtype[uint8]'> and <class 'numpy.dtype[datetime64]'> do not have a common DType. For example they cannot be stored in a single array unless the dtype is object.

Timus
  • 10,974
  • 5
  • 14
  • 28
kalidogg
  • 5
  • 3
  • Could you add some sample data to your question? Can you try if `debt[['Record_Date', 'Debt_Held_by_the_Public']].plot(x='Record_Date', y='Debt_Held_by_the_Public', kind='area')` works? – Timus Sep 21 '21 at 13:54
  • 1
    Thank you Timus. That worked. Much appreciated. – kalidogg Sep 21 '21 at 21:46

0 Answers0