0

I have a dataframe:

df1=pd.DataFrame(columns=["d","e"],data=[(3,1),(2,4),(8,4),(5,1)])

looking like this:

    d   e
0   3   1
1   2   4
2   8   4
3   5   1

and another df2=pd.DataFrame(columns=["a","b","c"],data=[(3,4,5)]) that looks like that:

    a   b   c
0   3   4   5

I want to add the one row dataframe to the bigger one repeating the same values across rows: Expected result is like this:

    d   e   a   b   c
0   3   1   3   4   5
1   2   4   3   4   5
2   8   4   3   4   5
3   5   1   3   4   5

1 Answers1

0

You can use DataFrame.merge:

import pandas as pd

df1 = pd.DataFrame(columns=["d","e"],data=[(3,1),(2,4),(8,4),(5,1)])                               
df2 = pd.DataFrame(columns=["a","b","c"],data=[(3,4,5)]

# Create a common key
df1['key'] = 0
df2['key'] = 0

result = df1.merge(df2, how='outer')

# Remove the key if you don't need it
del result['key']

result:

   d  e  a  b  c
0  3  1  3  4  5
1  2  4  3  4  5
2  8  4  3  4  5
3  5  1  3  4  5
Beniamin H
  • 2,048
  • 1
  • 11
  • 17