Fillna in multiple columns in place in Python Pandas

后端 未结 6 1948
北海茫月
北海茫月 2020-12-23 11:33

I have a pandas dataFrame of mixed types, some are strings and some are numbers. I would like to replace the NAN values in string columns by \'.\', and the NAN values in flo

6条回答
  •  遥遥无期
    2020-12-23 11:56

    There is a simpler way, that can be done in one line:

    df.fillna({'Name':0,'City':0},inplace=True)
    

    Not an awesome improvement but if you multiply it by 100, writting only the column names + ':0' is way faster than copying and pasting everything 100 times.

提交回复
热议问题