gpt4 book ai didi

python - 去掉 Pandas 中的多个名字

转载 作者:太空宇宙 更新时间:2023-11-04 04:28:37 27 4
gpt4 key购买 nike

我正在尝试将多名称列转换为 python 中的单名称列。现在,列名称如下所示:

   [('passengers', 'January'),
('passengers', 'February'),
('passengers', 'March'),
('passengers', 'April'),
('passengers', 'December'),
'Total']

但我正在尝试得到这个:

  ['January',
'February',
'March',
'April',
'December',
'Total']

有什么建议吗?

最佳答案

不是 Pandas :-):

l=[('passengers', 'January'),
('passengers', 'February'),
('passengers', 'March'),
('passengers', 'April'),
('passengers', 'December'),
'Total'] # Or pandas then get data to list.
print([i[-1] if isinstance(i,tuple) else i for i in l])

输出:

['January', 'February', 'March', 'April', 'December', 'Total']

关于python - 去掉 Pandas 中的多个名字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53074792/

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