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!
How about:
pd.concat([crawl(i) for i in range(1,18)])
You can do this:
df_list = [crawl(i) for i in range(1,18)]
final_df = pd.concat(df_list)
you could also use eval
to dynamically generate your object names.
df_list = pd.concat([eval(f'df{i}') for i in range(1,18)])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.