gpt4 book ai didi

python - 如何将已编译的元组(原始取自 Sql)传输到数组、系列或数据帧中?

转载 作者:行者123 更新时间:2023-11-30 22:11:11 26 4
gpt4 key购买 nike

  1. 我的是这样的:

    (('3177000000000053', '8018000000000498', datetime.datetime(2016, 9, 29, 21, 36, 42)), 
    ('3177000000000035', '8018000000000498', datetime.datetime(2016, 9, 29, 21, 37, 6 )))

这正是它在 mysql 数据库中的样子。

  1. 我想要的是这样的:

    [[1,2,3],
    [4,5,6]]

有series,dataframe,array,list.etc就可以了。我只是希望它易于管理,以便进一步分析过程。我已经尝试了几种方法来处理这个问题,例如 dataframe()、list(),甚至 pandas.replace(它给了我一个 tuple-cant-be-replaced 错误)。我是 python 的新手,谢谢你的回答!:)))))))))

最佳答案

如果你有元组的元组,你可以尝试下面的列表理解

import datetime

input_tuple = (('3177000000000053', '8018000000000498', datetime.datetime(2016, 9, 29, 21, 36, 42)),
('3177000000000035', '8018000000000498', datetime.datetime(2016, 9, 29, 21, 37, 6 )))

output_list = [[i for i in j] for j in input_tuple]

print(output_list)

关于python - 如何将已编译的元组(原始取自 Sql)传输到数组、系列或数据帧中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40080636/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com