Python Forum

Full Version: Counting and grouping
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I've got a dataset and would like to add the number of cases per year and put it in a new column. I used the following codes but wasn't able to get the total of 'complaints' for each year.
my_data_c = my_data[['created_date', 'complaint_type', 'incident_zip', 'latitude', 'longitude']]
my_data_comp = my_data_c.groupby(['complaint_type']).sum()
my_data_comp = my_data_comp.reset_index()
my_data_comp.loc[:, 'borough'] = my_data.loc[:,'borough']
my_data_comp.loc[:, 'created_date'] = my_data.loc[:, 'created_date']
my_data_comp['no_of_complaints'] = my_data_no_incidents
my_data_comp.head()
Lest, I forget, I split the 'created_date' column into year, month and day.
A screenshot of the original (part of) is added.İmage

Thanks in advance