'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!



Solution 1:[1]

How about:

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

Solution 2:[2]

You can do this:

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

final_df = pd.concat(df_list)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Quang Hoang
Solution 2 Mayank Porwal