Finding the Index with maximum number of rows

后端 未结 1 916
面向向阳花
面向向阳花 2021-01-27 11:39

My task:

For the next set of questions, we will be using census data from the United States Census Bureau. Counties are political and geographic subdivi

相关标签:
1条回答
  • 2021-01-27 12:17

    groupby simply returns a groupby object, you'll have to specify an aggregate function to be used on this object, e.g.

    df.groupby(by='STNAME').aggregate({'COUNTY': 'nunique'}).idxmax()[0]
    

    gives

    'Texas'
    

    See the pandas docs here for an introduction to grouping/aggregating.

    0 讨论(0)
提交回复
热议问题