gpt4 book ai didi

python - Python3.5中列表索引的快捷方式是什么?

转载 作者:太空宇宙 更新时间:2023-11-03 14:10:53 25 4
gpt4 key购买 nike

我想获取列名称,以便我可以添加到新的数据框。

In [241]: cursor.description
Out[241]:
(('a', None, None, None, None, None, None),
('b', None, None, None, None, None, None),
('c', None, None, None, None, None, None),
('d', None, None, None, None, None, None))
In [242]: rows
Out[242]:
[('Atlanta', 'Georgia', 1.25, 6),
('Tallahassee', 'Florida', 2.6, 3),
('Sacramento', 'California', 1.7, 5)]

我使用了相当复杂和乏味的方法:

frame = DataFrame(rows, columns = list(cursor.description[i][0] for i in range(len(cursor.description))))

是否有调用列名称的快捷方式?是否可以通过使用 zip() 来实现这一点?

最佳答案

这可能有用。它并不比你拥有的好多少。

columns = list(zip(*cursor.description))[0]

关于python - Python3.5中列表索引的快捷方式是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48504761/

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