Finding The Index With Maximum Number Of Rows
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 subdivisions of states in the Unite
Solution 1:
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.
Post a Comment for "Finding The Index With Maximum Number Of Rows"