IIUC you can just do
df = df.apply(lambda x: pd.to_numeric(x, errors='coerce') )
This will cause the duff values to be NaN, note that the presence NaNwill change dtype to float, as NaNit cannot be representedint
In [6]:
df = df.apply(pd.to_numeric, errors='coerce')
df
Out[6]:
a b
0 10.0 NaN
1 4.0 5.0
2 NaN 6.0
lambda not required but this is a more readable IMO
source
share