Jan-27-2020, 01:30 AM
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.
A screenshot of the original (part of) is added.![Click Photo To Enlarge İmage]()
Thanks in advance
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.
Thanks in advance