I've already read about various solutions, and tried the solution stated here: Pandas: Converting to numeric, creating NaNs when necessary
But it didn't really solve my problem:
I have a dataframe contains multiple columns, in where a column ['PricePerSeat_Outdoor']
contains some float values, some empty values, and some '-'
print type(df_raw['PricePerSeat_Outdoor'][99])
print df_raw['PricePerSeat_Outdoor'][95:101]
df_raw['PricePerSeat_Outdoor'] = df_raw['PricePerSeat_Outdoor'].apply(pd.to_numeric, errors='coerce')
print type(df_raw['PricePerSeat_Outdoor'][99])
Then I got:
<type 'str'>
95 17.21
96 17.24
97 -
98 -
99 17.2
100 17.24
Name: PricePerSeat_Outdoor, dtype: object
<type 'str'>
Values at row #98 and 99 didn't get converted. Again, I've already tried multiple methods including following but it just didn't work. Much appreciated if someone can give me some hints.
df_raw['PricePerSeat_Outdoor'] = df_raw['PricePerSeat_Outdoor'].apply(pd.to_numeric, errors='coerce')
Also, how can I convert multiple columns to numeric at once? Thanks.