你好。我需要将对象列转换为整数

问题描述 投票:0回答:1

我有 3 列对象,应该被解释为整数,但它们实际上存储为字符串,我必须将它们转换为整数。我应该使用 method.replace() 吗?

我尝试更换它们但没有成功

python integer
1个回答
0
投票
>>> column1 = ['123', '456', '789']
>>> print(type(column1[0])) 
<class 'str'>
>>> column1 = [int(x) for x in column1]
>>> print(type(column1[0])) 
<class 'int'>
© www.soinside.com 2019 - 2024. All rights reserved.