1

I am trying to write a python script to open a list of excel files, grab cell ranges, and put them all in a single dataframe.

After I create the dataframe to the excel read, I want to add the file name and some other to the dataframe related to the file that was opened and read. Essentially, my read code looks like this:

df = [pd.ExcelFile(file).parse('Daily Revenue',skiprows=1,skip_footer=1,index_col=None,parse_cols=(0,4),parse_dates=True,na_values=['N/A'])]

after initial open/read from excel, i get a dataframe that looks like this:

date    rev
2/1     500
2/2     600
2/3     700

i'm looking to modify this dataframe to make it look like:

 date   rev    file       group
 2/1    500    abc.xlsx   first
 2/2    600    abc.xlsx   first
 2/3    700    abc.xlsx   first

Where 'group' is a just the name of the person who sent the file.

How can I change my original df to append those 2 additional columns?

1
  • why are you putting the dataframe in a 1-element list? Commented Mar 1, 2015 at 5:40

1 Answer 1

2
df['file'] = 'abc.xlsx'
df['group'] = 'first'
Sign up to request clarification or add additional context in comments.

2 Comments

that's so tidy! fixed to use @Paul H 's improvement. (@paul-h? @PaulH?)
thank you very much! my admiration for python grows again at the simplicity of the solution!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.