如何基于另一列填充熊猫中的数字缺失值

问题描述 投票:0回答:1

在这里我需要在熊猫中插入数字列

样本数据:

Age   Time_of_service

42       4

24       5

nan      27

26       4

31       5

54       21

21       2

Nan      32

45       18

19       0

65      35

nan       3

这里Age&Time_of_Service列都高度相关。根据以下条件,我需要估算缺失的值

Time_of_Service >30
age = 60
Time_of_Service in (20,30)
age = 45
Time_of_Service in (10,20)
age = 35
Time_of_Service in (0,10)
age = 25

如何基于上述条件使用Python估算缺失值?

python pandas numpy dataframe missing-data
1个回答
0
投票

使用cut进行装箱,然后将输出转换为整数,并用cut替换Age列中的缺失值:

Series.fillna
© www.soinside.com 2019 - 2024. All rights reserved.