visit_date | sex | age | marital_status |
---|---|---|---|
0 2021-04-05 | Female | 66 | Widowed |
1 2021-04-05 | Female | 65 | Widowed |
2 2021-04-05 | Female | 39 | Married |
3 2021-04-05 | Male | 56 | Married |
4 2021-04-05 | Female | 31 | Married |
5 2021-04-05 | Female | 24 | Single |
6 2021-04-05 | Male | 37 | Married |
7 2021-04-05 | Female | 43 | Widowed |
8 2021-04-05 | Male | 29 | Married |
9 2021-04-05 | Male | 44 | Single |
CodePudding user response:
If I understood correctly this should work
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame(data)
df['visit_date'] = pd.to_datetime(df['visit_date'])
attendance = df.groupby(pd.Grouper(key="visit_date", freq='M')).size().reset_index(name='attendance')
attendance.plot(x='visit_date', y='attendance', kind='line')
plt.show()