这是我的数据框:
data = {'transit_time':[1,1,2,2,3,3],
'orig_state':['UT','UT','UT','UT','UT','UT'],
'dest_state':['CA','CA','AZ','AZ','NY','NY'],
'GEOID':['01','01','02','02','03','03'],
'dest_state_fn':['California','California','Arizona','Arizona','New York','New York'],
'dest_county_name':['county1','county1','county2','county2','county3','county3']
}
df = pd.DataFrame(data,columns = ['transit_time','orig_state','dest_state','GEOID','dest_state_fn','dest_county_name'])
print (df)
transit_time orig_state dest_state GEOID dest_state_fn dest_county_name
0 1 UT CA 01 California county1
1 1 UT CA 01 California county1
2 2 UT AZ 02 Arizona county2
3 2 UT AZ 02 Arizona county2
4 3 UT NY 03 New York county3
5 3 UT NY 03 New York county3
Run Code Online (Sandbox Code Playgroud)
我想获得一个按 GEOID、dest_county_name、AVG(transit time)、COUNT(*) 分组的数据框,如下图所示: