pandas replace null values for a subset of columns

后端 未结 3 2021
無奈伤痛
無奈伤痛 2021-02-14 16:07

I have a data frame with many columns, say:

df:
name   salary  age   title
John      100   35    eng
Bill      200  NaN    adm
Lena      NaN   28    NaN
Jane             


        
3条回答
  •  说谎
    说谎 (楼主)
    2021-02-14 16:58

    It is not so beautiful, but it works:

    df.salary.fillna(-1, inplace=True)
    df.age.fillna(-1, inplace=True)
    df
    >>>    name  salary   age title
        0  John   101.0  35.0   eng
        1  Bill   200.0  -1.0   adm
        2  Lena    -1.0  28.0   NaN
        3  Jane   120.0  45.0   eng
    

提交回复
热议问题