'Can't convert column with pandas.to_numeric
I have a column of data, here is a snip of it:
a = data["hs_directory"]["lat"][:5]
0 40.67029890700047
1 40.8276026690005
2 40.842414068000494
3 40.71067947100045
4 40.718810094000446
Name: lat, dtype: object
I try to convert it to numerical with python, but fail:
pandas.to_numeric(a, errors='coerce')
This line does nothing, the dtype is still "object" and I can't do mathematical operations with the column. What am I doing wrong?
Solution 1:[1]
As discussed in the comments, let me post the answer for future readers:
try:
df1=pd.to_numeric(a,errors='coerce')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | MattR |