Andrey Lukyanenko
Andrey Lukyanenko

Reputation: 3851

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?

Upvotes: 1

Views: 5386

Answers (1)

MattR
MattR

Reputation: 5126

As discussed in the comments, let me post the answer for future readers:

try:

df1=pd.to_numeric(a,errors='coerce')

Upvotes: 2

Related Questions