Say I have a column in a data frame that contains some numbers and some not 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 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: -
python pandas
Amelio Vazquez-Reina Aug 25 '13 at 22:04 2013-08-25 22:04
source share