1

I have a pandas dataframe that I've tried to group by year on 'Close Date' and then plot 'ARR (USD)' on the y-axis against the year on the x-axis.

All seems fine after grouping:

sumyr = brandarr.groupby(brandarr['Close Date'].dt.year,as_index=True).sum()

         ARR (USD)
Close Date  
2017    17121174.33
2018    15383130.32

But when I try to plot:

trace = [go.Bar(
x=sumyr['Close Date'],
y=sumyr['ARR (USD)']
)]

I get the error: KeyError: 'Close Date'

I'm sure it's something stupid, I'm a newbie, but I've been messing with it for an hour and well, here I am. Thanks!

1 Answers1

1

In your groupby function you have used as_index=True so Close Date is now an index. If you want to have access to an index, use pandas .loc or .iloc. To have access to the index values directly, use:

sumyr.index.tolist()

Check here: Pandas - how to get the data frame index as an array

Wariored
  • 1,303
  • 14
  • 25