replacing empty strings with NaN in Pandas

前端 未结 2 2018
天涯浪人
天涯浪人 2020-12-30 05:26

I have a pandas dataframe (that was created by importing a csv file). I want to replace blank values with NaN. Some of these blank values are empty and some contain a (varia

2条回答
  •  攒了一身酷
    2020-12-30 06:09

    Indicate it has to start with blank and end with blanks with ^ and $ :

    df.replace(r'^\s*$', np.nan, regex=True, inplace = True)
    

提交回复
热议问题