Home > Mobile >  Combine 2 one-row dataframes in the same row
Combine 2 one-row dataframes in the same row

Time:02-05

So I have 2 dfs with the following structure

   DF1: A B   DF2:  C D
        1 2         3 4

And I would like to combine them like this:

DF: A B C D
    1 2 3 4

But instead I get this with every function I tried (merge, join, concat):

DF: A  B  C  D
    1  2  NA NA
    NA NA 3  4

How can I merge them like I want them to?

CodePudding user response:

How have you tried pandas.concat?

import pandas as pd

out = pd.concat([df1, df2], axis=1)

CodePudding user response:

Use pd.concat with axis=1:

df = pd.concat([df1, df2], axis=1)
  •  Tags:  
  • Related