只需使用
replace:
In [106]:df.replace('N/A',np.NaN)Out[106]: x y0 10 121 50 112 18 NaN3 32 134 47 155 20 NaN您正在尝试的操作称为链索引:http :
//pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-
copy
您可以
loc用来确保对原始dF进行操作:
In [108]:df.loc[df['y'] == 'N/A','y'] = np.nandfOut[108]: x y0 10 121 50 112 18 NaN3 32 134 47 155 20 NaN



