0

I have data (labeled as df) that looks like this(below) where the 'DATE' column is formatted as such -> MM/DD/YYYY.

data table

I then need to group the available accident data by month.

Anyone know how to do this by first converting 'DATE' column to a datetime type, setting the index using set_index and then using groupby to group by month?

amyungju
  • 3
  • 1

2 Answers2

0

If your column is not is not already in datetime:

df['Date'] = pd.to_datetime(df['Date'])

Then, do following to groupby month:

df.groupby(df.Date.dt.month)[columns_you_need_to_groupby_on].mean()
-1

Maybe this will help you How do I convert a datetime to date?

I looked at your table and it looks like you could just sort the table by date and you'd be fine

monojohnny
  • 5,894
  • 16
  • 59
  • 83