Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (17.6k points)

import pandas as pd

import os

import glob

all_data = pd.DataFrame()

for f in glob.glob("output/test*.xlsx")

    df = pd.read_excel(f)

    all_data = all_data.append(df, ignore_index=True)

I want to put multiple xlsx files into one xlsx. the excel files are in the output/test folder. The columns are the same, in all but I want concat the rows. the above code doesn't seem to work

1 Answer

0 votes
by (41.4k points)

If we will use list with concatenation, then it will work fine.

Declaring all_data as a list.

all_data = [] for f in glob.glob("output/test/*.xlsx"): 

all_data.append(pd.read_excel(f))

Now, concatenate all_data.

df = pd.concat(all_data, ignore_index=True)

If you wish to learn about Python visit this Python Course.

Related questions

0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...