简体   繁体   English

无法使用pandas.to_numeric转换列

[英]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: 我尝试使用python将其转换为数值,但失败:

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. 该行不执行任何操作,dtype仍然是“对象”,并且我无法对该列进行数学运算。 What am I doing wrong? 我究竟做错了什么?

As discussed in the comments, let me post the answer for future readers: 正如评论中所讨论的,让我将答案发布给未来的读者:

try: 尝试:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM