Generation

generate functionFri, 03 Feb 2023

There is a df_new Pandas dataframe: id route operator group_name district injury_result incident_type victim_category victim_age 2 3.0 1 London General Go-Ahead Southwark NaN Onboard Injuries 7 10 3 4.0 4 Metroline Metroline Islington NaN Onboard Injuries 7 2 4 5.0 5 East London Stagecoach Havering NaN Onboard Injuries 7 8 5 6.0 5 East London Stagecoach None London Borough NaN Onboard Injuries 7 8 Count which routes had the most incident_types with a value >= 5. Sort them in descending order by incident_type column

df_new.groupby(['route', 'incident_type']).count()['id'] df_new.groupby(['route', 'incident_type'])['id'].count() df_new.groupby(['route', 'incident_type'])['id'].size() df_new[df_new['incident_type'] >= 5].groupby(['route', 'incident_type']).count()['id'] df_new[df_new['incident_type'] >= 5].groupby(['route', 'incident_type']).size() df_new[df_new['incident_type'] >= 5].groupby(['route', 'incident_type'])['id'].size() df_new[df_new['incident_type'] >= 5].groupby(['route', 'incident_type'])['id'].size().sort_values(ascending=False)

Questions about programming?Chat with your personal AI assistant