I have two data frames

dataframe 1

col1 col2

1 A

1 B

2 C

5 Z

4 Q

dataframe 2

col1 col2

1 A

1 B

2 E

3 X

4 R

4 S

I am performing an outer merge

merge = pd.merge(dataframe1, datagrame2, on="col1", how='outer')

I get

col1 col2_x col2_y

1 A A

1 A B

1 B A

1 B B

2 C E

5 Z NAN

3 NAN X

4 Q R

4 Q S

How do I get the output as below

col1 col2_x col2_y

1 A A

1 B B

2 C E

5 Z NAN

3 NAN X

4 Q R

4 Q S

Any help will be appreciated. Thank you

dataframe 1

col1 col2

1 A

1 B

2 C

5 Z

4 Q

dataframe 2

col1 col2

1 A

1 B

2 E

3 X

4 R

4 S

I am performing an outer merge

merge = pd.merge(dataframe1, datagrame2, on="col1", how='outer')

I get

col1 col2_x col2_y

1 A A

1 A B

1 B A

1 B B

2 C E

5 Z NAN

3 NAN X

4 Q R

4 Q S

How do I get the output as below

col1 col2_x col2_y

1 A A

1 B B

2 C E

5 Z NAN

3 NAN X

4 Q R

4 Q S

Any help will be appreciated. Thank you