简体   繁体   English

从元组数组中删除引号和逗号

[英]Removing quotation marks and comma from array of tuples

I created an array of tuples from a column in a dataframe as such: 我是这样从数据框中的列创建元组数组的:

 subset = df[['sRGB']]
 tuples = [tuple(x) for x in subset.values]

Although, in the data frame, the values in the 'sRGB' column are 3 consecutive numbers separated by a comma, the array of tuples comes out as the following with additional quotation marks and a comma: 尽管在数据帧中,“ sRGB”列中的值是3个连续的数字,中间用逗号分隔,但元组数组如下所示,但带有附加引号和逗号:

在此处输入图片说明

I am looking for a way to remove the quotation marks and the unnecessary comma inside each tuple, so that the array of tuples looks like this: 我正在寻找一种方法来删除每个元组内的引号和不必要的逗号,以使元组数组如下所示:

[(45,21, 31), (54, 14, 33)...] [(45,21,31),(54,14,33)...]

I would greatly appreciate any guidance as I have already spent 2 hours on this! 我已经花了2个小时了,我将不胜感激任何指导!

Thanks in advance! 提前致谢!

尝试这个:

tuples = [tuple([int(y) for y in x[0].split(",")]) for x in tuples]

你可以做:

tuples = [tuple( map(int, val[0].split(','))) for val in tuples]

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

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