【发布时间】:2018-05-07 14:08:39
【问题描述】:
我希望根据多个标题条件查询信息。在读取具有 6 个标题行的文件时,看起来标题被读取为 1 个大列表而不是 6 个数组。为了使用多索引函数,我需要转换为数组吗?这是怎么做到的?
data = pd.read_csv('data.csv', header = [0,1,2,3,4,5], index_col = 0)
list(data)
[('US Banks', 'Main', 'Sectors', 'ALL', 'ALL', 'Modified Duration'),
('US Banks', 'Main', 'Sectors', 'ALL', '1-3', 'Modified Duration'),
('US Banks', 'Main', 'Sectors', 'ALL', '3-5', 'Modified Duration'),
('US Banks', 'Main', 'Sectors', 'ALL', '5-7', 'Modified Duration'),
('US Banks', 'Main', 'Sectors', 'ALL', '7-10', 'Modified Duration'),
('US Banks', 'Main', 'Sectors', 'ALL', '10+', 'Modified Duration'),...]
【问题讨论】:
标签: python pandas dataframe multi-index