MultiIndex Group By in Pandas Data Frame

前端 未结 2 2019
野的像风
野的像风 2021-02-03 13:56

I have a data set that contains countries and statistics on economic indicators by year, organized like so:

Country  Metric           2011   2012   2013  2014
          


        
2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-03 14:22

    Is this what you are looking for:

    df = df.groupby(['Metric'])
    df.get_group('GDP')
    
       Country Metric  2011    2012    2013    2014
    0    USA     GDP     7      4       0       2
    2    GB      GDP     8      7       0       7
    4    FR      GDP     5      0       0       1
    

提交回复
热议问题