idxmax() doesn't work on SeriesGroupBy that contains NaN

前端 未结 3 1891
借酒劲吻你
借酒劲吻你 2021-01-27 04:41

Here is my code

from pandas import DataFrame, Series
import pandas as pd
import numpy as np
income = DataFrame({\'name\': [\'Adam\', \'Bill\', \'Chris\', \'Dave\         


        
3条回答
  •  梦毁少年i
    2021-01-27 05:35

    grouped['income'].agg(lambda x : x.idxmax())
    
    
    Out[]:
    age
    (20, 30]     1
    (30, 40]   NaN
    (40, 50]     2
    (50, 60]     4
    Name: income, dtype: float64
    

    and then you can do the following to get the data

    income.ix[result.values].dropna()
    

提交回复
热议问题