1

Merging 2 dataframes without changing shape

I have a dataframe like this:

A B
1 2
3 4
9 1

And a dataframe like this:

A C
1 3
2 4
3 5
4 6

I would like to merge the first dataframe and the second one to give a output like this:

A B C
1 2 3
3 4 5
9 1 NaN

Submitted July 18th 2021 by Admin

Answers
0

Try:

x = df1.merge(df2, on="A", how="left")
print(x)

Prints:

 A B C
0 1 2 3.0
1 3 4 5.0
2 9 1 NaN

Admin | 1 week ago



Relevant Questions