1

I have the below dataframe with index: DateTime

                  ghi        dni       dhi  ...       Ws  wind_speed  temp_air
DateTime                                    ...                               
2015-01-31   63079.57   37115.92  25963.65  ...  1589.20           0     14860
2015-02-28   68303.53   34683.19  33620.34  ...  1796.91           0     13440
2015-03-31  138789.55   88291.41  50498.14  ...  1647.59           0     14880
2015-04-30  135415.64   70234.19  65181.45  ...  1474.14           0     14400

I used the following and it works:

df1.plot(kind='bar',x='**gni**',y='ghi')

but if I do the following, it doesn´t:

df1.plot(kind='bar',x='**DateTime**',y='ghi')

Could you explain me why?

PMendes
  • 29
  • 4

1 Answers1

0

Very similar question here. You could either omit x=... or use .reset_index() to get a column to plot as x:

import pandas as pd

# dummy df:
df1 = pd.DataFrame({'ghi': [1,2,1,3,1,4],
                    'DateTime': pd.date_range('2015-01', '2015-06', freq='MS')})
df1.set_index('DateTime', inplace=True)

# don't specify x=...:
ax = df1.plot(kind='bar', y='ghi')
# or use the index as a column:
ax = df1.reset_index().plot(kind='bar', x='DateTime', y='ghi')

# nicer x labels, e.g.:
ax.xaxis.set_ticklabels([i.strftime('%Y-%m-%d') for i in df1.index], rotation=45)
FObersteiner
  • 22,500
  • 8
  • 42
  • 72