Concatenate Two Dataframes Pandas with single Row

Viewed 5401

I have a dataframe df that looks like:

   one  three  two
0  1.0   10.0  4.0
1  2.0    3.0  3.0
2  3.0   22.0  2.0
3  4.0    1.0  1.0

I have another single row dataframe df2 that looks like:

     a    b    m    u
0  1.0  2.0  1.0  4.0

I want to concatenate the two to end up with:

   one  three  two    a    b    m    u
0  1.0   10.0  4.0  1.0  2.0  1.0  4.0
1  2.0    3.0  3.0  1.0  2.0  1.0  4.0
2  3.0   22.0  2.0  1.0  2.0  1.0  4.0
3  4.0    1.0  1.0  1.0  2.0  1.0  4.0

I tried:

df3 = pd.concat([df, df2], axis=1, ignore_index=True)

     0     1    2    3    4    5    6
0  1.0  10.0  4.0  1.0  2.0  1.0  4.0
1  2.0   3.0  3.0  NaN  NaN  NaN  NaN
2  3.0  22.0  2.0  NaN  NaN  NaN  NaN
3  4.0   1.0  1.0  NaN  NaN  NaN  NaN

Err Wrong answer...

How can I sort this out?

Many thanks.

2 Answers
Related