0

I am trying to read multiple excel files into a Pandas Dataframe.

I have got the below code in place:

allFiles = glob.glob(base2 + "/*.xls"). <<-- Reading from path where all files are stored
list_ = []
for file_ in allFiles:
    df = pd.read_excel(io.BytesIO(open(file_, 'rb').read()), sheet_name='Sheet1') <<-- using io module to read the file as there are some issue with the text format
    list_.append(df)

print(list_)
file = pd.DataFrame(list_)

When I open the Dataframe csv file, I see entire contents of a single file all in a single row. I am trying to have each row from the source file said in a separate row in the file output.

1 Answer 1

1

Rather than create the pd.DataFrame based on the list, use pd.concat to concatenate them, i.e.

file = pd.concat(list_)
Sign up to request clarification or add additional context in comments.

1 Comment

You're welcome. If you found the answer helpful, you can mark it as accepted.

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.