Pandas Fillna Mode

后端 未结 6 1278
借酒劲吻你
借酒劲吻你 2021-02-05 12:13

I have a data set in which there is a column known as Native Country which contain around 30000 records. Some are missing represented by NaN so I thoug

6条回答
  •  情话喂你
    2021-02-05 12:32

    You can get the number 'mode' or any another strategy

    num = data['Native Country'].mode()
    data['Native Country'].fillna(num, inplace=True)
    

    or in one line like this

    data['Native Country'].fillna(data['Native Country'].mode()[0], inplace=True)
    

提交回复
热议问题