首页 > 解决方案 > Python - 从列表中删除引号

问题描述

我有一个带有数字列表的数据框。打印列表时,我要删除前面和末尾的引号。我无法用替换功能替换它们。

a = df.iloc[0]['ids']
b = [a]
b (Output) 
['2769734487041924, 7608779650164612'] <-- one quotation mark at beginning and end

我想要的(手动创建):

row_ids = [1234, 4567]
row_ids (Output)
[1234, 4567] <-- That's the format I want to get the list to, without the quotation marks

b和row_ids数据类型返回为“列表”,因此必须有一种方法可以使列表不带引号。

标签: python

解决方案


我认为a是一个字符串,因此可以从中获取所需b的整数列表

b = list(map(int, a.split(",")))

推荐阅读