How to set a cell to NaN in a pandas dataframe

前端 未结 8 968
时光取名叫无心
时光取名叫无心 2020-12-04 09:51

I\'d like to replace bad values in a column of a dataframe by NaN\'s.

mydata = {\'x\' : [10, 50, 18, 32, 47, 20], \'y\' : [\'12\', \'11\', \'N/A\', \'13\', \         


        
8条回答
  •  星月不相逢
    2020-12-04 10:08

    Most replies here need to import numpy as np

    There is a built-in solution into pandas itself: pd.NA, to use like this:

    df.replace('N/A', pd.NA)
    

提交回复
热议问题