I have an excel file foo.xlsx with about 40 sheets sh1, sh2, etc. Each sheet has the format:
area cnt name\nparty1 name\nparty2
blah 9 5 5
word 3 7 5
In each sheet I want to rename the variables with the format name\nparty to only have the party as a label. Example output:
area cnt party1 party2 sheet
bacon 9 5 5 sh1
spam 3 7 5 sh1
eggs 2 18 4 sh2
I am reading in the file with:
book = pd.ExcelFile(path)
And then wondering if I need to do:
for f in filelist:
df = pd.ExcelFile.parse(book,sheetname=??)
'more operations here'
# only change column names 2 and 3
i, col in enumerate(df):
if i>=2 and i<=3:
new_col_name = col.split("\n")[-1]
df[new_col_name] =
Or something like that?