Group a dataset through python. for eg. these 4 rows : REPORT_DAT HOOD_140 REPORT_DOW DIVISION LOCATION_TYPE PREMISES_TYPE
Question:
Group a dataset through python.
for eg. these 4 rows :
REPORT_DAT | HOOD_140 | REPORT_DOW | DIVISION | LOCATION_TYPE | PREMISES_TYPE | OFFENCE | Neighbourhood | Count_of_police_force | Average Individual Employment Income | Population | Unemployment Rate | Low Income population(LIM-AT) | EVENT_UNIQUE_ID |
2018-01-01 | 76 | Monday | D52 | Commercial Dwelling Unit (Hotel, Motel, B & B, Short Term Rental) | Commercial | Assault | Bay Street Corridor | 259 | 63,009 | 25,797 | 10.2 | 9,665 | 1 |
2018-01-01 | 76 | Monday | D52 | Other Commercial / Corporate Places (For Profit, Warehouse, Corp. Bldg | Commercial | Assault | Bay Street Corridor | 259 | 63,009 | 25,797 | 10.2 | 9,665 | 1 |
2018-01-02 | 76 | Tuesday | D52 | Apartment (Rooming House, Condo) | Apartment | Assault | Bay Street Corridor | 259 | 63,009 | 25,797 | 10.2 | 9,665 | 1 |
2018-01-02 | 76 | Tuesday | D52 | Streets, Roads, Highways (Bicycle Path, Private Road) | Outside | Assault | Bay Street Corridor | 259 | 63,009 | 25,797 | 10.2 | 9,665 | 1 |
I want to group the 2 dates 1st jan had sum(event_unique_id) =2 , same way 2nd jan had sum(event_unique_id) =2.
i use this code :
grouped_crimedf= crime_df.groupby(['HOOD_140','REPORT_DAT','REPORT_DOW','DIVISION','LOCATION_TYPE','PREMISES_TYPE','OFFENCE','Neighbourhood','Count_of_police_force','Average Individual Employment Income','Population','Unemployment Rate','Low Income population(LIM-AT)']).agg({'EVENT_UNIQUE_ID': 'count'}).reset_index()
I have to use all the columns because if i drop some of them from the above statement then i dont get them in the grouped_df dataset which means i cannot apply LR later on on these columns. how can i get all the columns and at the same time group it based on only date and hood_140.
International Marketing And Export Management
ISBN: 9781292016924
8th Edition
Authors: Gerald Albaum , Alexander Josiassen , Edwin Duerr