So I imported all sheets from an excel file using pd.read_excel('df.xlsx',sheet_name=None)
.
I have a dict with key value pairs.
In all these sheets there is a table present. I want to make the first column as index and then insert a column from a separate dataframe that I already have.
What is the best way to approach this, should I save all sheets in to dfs individually or is there a way to loop over key value pairs?
Info | Col A | Col B |
---|---|---|
First Name | ||
Second Name | ||
Phone |
And then I wanted to insert a column in all sheets so I was thinking I would use pd.insert()
CodePudding user response:
As you have a dict of key, values, where each value is a df, you can iterate over them and first set the index, next create a column based on the other df. Use:
for name, df in data.items():
df = df.set_index('info')
df['new col'] = another_df['specified col']