Error using pandas read_excel (header = [0,1])

I am trying to use pandas read_excel to work with a file. The file has two header columns, so I'm trying to use the multiIndex function separately from the keyword argument.

import pandas as pd, os 

"""data in 2015 MOR Folder"""
filename = 'MOR-JANUARY 2015.xlsx'

print(os.path.isfile(filename))

df1 = pd.read_excel(filename, header=[0,1], sheetname='MOR')

print(df1)

the error I get is ValueError: The length of the new names must be 1, received 2. The file is in this folder with the google file https://drive.google.com/drive/folders/0B0ynKIVAlSgidFFySWJoeFByMDQ?usp=sharing I am trying to execute a solution posted here Read multi-heading sheets with Pandas

+4
source share
1 answer

, , pandas excel, . , . , , . , ffill . Excel , , .


, .

filename = 'MOR-JANUARY 2015.xlsx'
df1 = pd.read_excel(filename, sheetname='MOR', header=None)

vals = df1.values

mux = pd.MultiIndex.from_arrays(df1.ffill(1).values[:2, 1:], names=[None, 'DATE'])

df1 = pd.DataFrame(df1.values[2:, 1:], df1.values[2:, 0], mux)
+2

Source: https://habr.com/ru/post/1664346/


All Articles