Joining two DataFrames with same columns

Hi there,

I would like to join two DataFrames that have the same column, let’s say:

DataFrameA:
country GDP
Germany 1

DataFrameB:
country GDP
USA 2

The resulting DataFrame should be:
country GDP
Germany 1
USA 2

But through join(DataFrameA,DataFrameB,on = :country, kind= :outer) I get:
country GDP GDP_1
Germany 1 NA
USA NA 2

Is it just another kind of join or a different command altogether?

Thanks a lot!

2 Likes

I think you want vcat() to concatenate your DataFrames.

8 Likes

I also found this answer on StackOverflow for when only a subset of the columns are the same:

join(df1, df2, kind = :outer, on = intersect(names(df1), names(df2)))

https://stackoverflow.com/a/53747354/371843

1 Like