Akira
Akira

Reputation: 2870

How to concatenate efficiently a list of dataframes?

I have a function crawl that input an integer and output a dataframe. To concatenate dataframes df1, df2, df3, we can use pandas.concat([df1, df2, df3]). I would like to ask of there is an efficient way to concatenate df1,..., df17 without writing a long list df1 = crawl(1),..., df17 = crawl(17).

Thank you so much!

Upvotes: 3

Views: 967

Answers (2)

Mayank Porwal
Mayank Porwal

Reputation: 34086

You can do this:

df_list = [crawl(i) for i in range(1,18)]

final_df = pd.concat(df_list)

Upvotes: 1

Quang Hoang
Quang Hoang

Reputation: 150785

How about:

pd.concat([crawl(i) for i in range(1,18)])

Upvotes: 5

Related Questions