For example, The dataframe looks like:
DF=pd.DataFrame([[1,1],[2,120],[3,25],[4,np.NaN],[5,45]],columns=["ID","Age"])
In the Age column, the values below 5 and greater than 100 have to converted to NaN.
Any help is appreciated!
Using where
and between
df.Age=df.Age.where(df.Age.between(5,100))
df
ID Age
0 10 NaN
1 20 NaN
2 30 25.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With