我正在尝试将多名称列转换为python中的单名称列。现在,列名称如下所示:
[('passengers', 'January'),
('passengers', 'February'),
('passengers', 'March'),
('passengers', 'April'),
('passengers', 'December'),
'Total']
但是我试图得到这个:
['January',
'February',
'March',
'April',
'December',
'Total']
有什么建议么?
最佳答案
不是熊猫:-):
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']