links to "Stackoverflow question" I am new to Python and tried the program in the links however, I am getting the below error, am I missing anything here? Could you point me out?
...............................
import matplotlib.pyplot as plt
import pandas as pd
df = pd.DataFrame({
'weight':[1, 2, 3, 4],
'date':['2011-05-01', '2013-10-10', '2015-12-17', '2017-10-29']
})
df['date'] = pd.to_datetime(df['date'])
df1 = df.groupby(df['date'].dt.to_period('M')).sum()
df1 = df1.resample('M').asfreq().fillna(0)
plt.figure();
df1.plot(x='date', y='weight', kind='bar')
.......................................... Traceback (most recent call last):
File "/PycharmProjects/hellopython/hello_world", line 24, in
df1.plot(x='date', y='weight', kind='bar')
File "\PycharmProjects\hellopython\venv\lib\site-
packages\pandas\plotting_core.py", line 920, in call
elif not isinstance(data[x], ABCSeries):
File "\PycharmProjects\hellopython\venv\lib\site-packages\pandas\core\frame.py", line 3024, in getitem
indexer = self.columns.get_loc(key)
File "\PycharmProjects\hellopython\venv\lib\site-
packages\pandas\core\indexes\base.py", line 3082, in get_loc
raise KeyError(key) from err
KeyError: 'date'