简体   繁体   中英

Vertically concatenate multiple dataframes

So I'm trying to intertwine about 3 dataframes and the result should look like this:

df1

A

D

G


df2

B

E

H


df3

C

F

I


Resulting df:

A

B

C

D

E

F

G

H

I

I tried:

for i in len(df1+df2+df3):
    final_df.append(i)

I want to do this as efficiently as possible and with n dataframes

Referring to Spark unionAll multiple dataframes :

You can simply put all the data frames into a list, and do a unionAll on them, like so:

from functools import reduce
from pyspark.sql import DataFrame

dfs = [df1,df2,df3]
df = reduce(DataFrame.unionAll, dfs)

Use pd.concat :

pd.concat([df1, df2, df3], ignore_index=True)

You can concat as many dataframes as you want.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM