【发布时间】:2020-10-03 09:48:40
【问题描述】:
我有以下数据。
当我检查这些字段的 DType 时,它显示为 object,现在我的要求是将它们转换为 int64
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 area_type 3 non-null object
1 availability 3 non-null object
2 location 3 non-null object
3 size 3 non-null object
4 society 3 non-null object
有人可以帮我转换它们的代码吗?我尝试使用下面的代码,但它给了我一个错误。
dataset['area_type'] = dataset['area_type'].str.replace(',','').astype(int)
错误
ValueError: invalid literal for int() with base 10: 'Super built-up Area'
【问题讨论】:
-
你想要的输出是什么?因为如果字符串不是数字字符串,则无法将字符串转换为 int...
-
我打算执行线性回归,所以为了做到这一点,我必须将它们转换为整数。
-
那么你应该使用one-hot-encoding或类似this的东西,而不是函数
int()... -
您能上传数据吗?和所需的输出?
标签: python python-3.x pandas encoding one-hot-encoding