Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Counting and grouping
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Grouping Data based on 30% bracket purnima1 0 955 Feb-16-2023, 07:14 PM
Last Post: purnima1
  sns point plot grouping Mekala 0 1,502 Jul-24-2020, 04:06 PM
Last Post: Mekala
  Grouping Integers mjack24 4 2,663 Feb-08-2019, 11:12 AM
Last Post: FranSPG

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020