简体   繁体   中英

Concatenate Pandas dataframes with different set of columns

df1 has columns A, B, C, D, E

df2 has columns A, B, D

How to concatenate them in order to have a resulting dataframe that has rows of df1 and df2, values of A, B and D will be extended from df2 on df1, and columns C and E will be filled with NaN because df2 has no data for them?

There is a function called concat

pd.concat([df1,df2])

The input must be a iterable, so put them into a list;)

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