这是我的数据框,我希望使用列["State", "RegionName"]
RegionName State Metro CountyName SizeRank
1 Los Angeles CA Los Angeles-Long Beach-Anaheim 2
2 Chicago IL Chicago Cook 3
3 Philadelphia PA Philadelphia Philadelphia 4
4 Phoenix AZ Phoenix Maricopa 5
5 Las Vegas NV Las Vegas Clark 6
6 San Diego CA San Diego San Diego 7
7 Dallas TX Dallas-Fort Worth Dallas 8
8 San Jose CA San Jose Santa Clara 9
9 Jacksonville FL Jacksonville Duval 10
我的代码:
multi_gdp_df = gdp_df.set_index([gdp_df['State'], gdp_df['RegionName']], drop=False)
然后我得到的结果是,该地区属于同一州“ CA”没有分组
Metro CountyName SizeRank
State RegionName
CA Los Angeles Los Angeles-Long Beach-Anaheim Los Angeles 2
IL Chicago Chicago Cook 3
PA Philadelphia Philadelphia Philadelphia 4
AZ Phoenix Phoenix Maricopa 5
NV Las Vegas Las Vegas Clark 6
CA San Diego San Diego San Diego 7
TX Dallas Dallas-Fort Worth Dallas 8
CA San Jose San Jose Santa Clara 9
FL Jacksonville Jacksonville Duval 10
如何使具有区域组的数据框处于相同状态?