Suppose I have two columns time (e.g. 2019-02-13T22:31:47.000000000) and amount (e.g. 15). The time column might have duplicates.
What's the best way to resample amount into daily/monthly/yearly then plot?
I tried:
df.resample('M', on='time').sum().plot(x='time', y='amount')
but it says:
raise KeyError(key) from err
if is_scalar(key) and isna(key) and not self.hasnans:
KeyError: 'time'
Already verified that time is datetime (without null values):
df['time'].isnull().any()
false
Amount is float as well.
CodePudding user response:
The documentation says
The object must have a datetime-like index
So, try:
df.set_index('time').resample('M').sum().plot(x='time', y='amount')