.groupby & .fillna with median

后端 未结 2 1061
南笙
南笙 2021-01-25 06:30
# Create a groupby object: by_sex_class
by_sex_class = titanic.groupby([\"sex\",\"pclass\"]).count()

# Write a function that imputes median
def impute_median(series):
          


        
2条回答
  •  猫巷女王i
    2021-01-25 07:23

    I will recommend using this

    df['age'].fillna(df.groupby(["sex","pclass"])['age'].transform('median'),inplace=True)
    

提交回复
热议问题