I have a dataframe data
that looks this this:
age
0 .
1 1.2
2 9
3 .
I want to convert all the rows that have .
to an empty value (or np.nan
).
My desired output would be:
age
0
1 1.2
2 9
3
I tried two different regular expressions which both didn't work:
data['age'] = data['age'].str.replace(r'^(.)$', '')
data['age'] = data['age'].str.replace(r'\D', '')
Both of the results:
age
0
1 NaN
2 NaN
3