Say I have a column in a dataframe that has some numbers and some non-numbers
>> df['foo']
0 0.0
1 103.8
2 751.1
3 0.0
4 0.0
5 -
6 -
7 0.0
8 -
9 0.0
Name: foo, Length: 9, dtype: object
How can I convert this column to np.float
, and have everything else that is not float convert it to NaN
?
When I try:
>> df['foo'].astype(np.float)
or
>> df['foo'].apply(np.float)
I get ValueError: could not convert string to float: -