DataFrame D1
like:
DataFrame D2
like:
I want to merge them like:
I used pd.concat
, get this(This is not what I want):
How can I append C,D..... to every row in a Pandas DataFrame D1.
DataFrame D1
like:
DataFrame D2
like:
I want to merge them like:
I used pd.concat
, get this(This is not what I want):
How can I append C,D..... to every row in a Pandas DataFrame D1.
If you always have only one row in the second dataframe, you can do:
for col in df2:
df1[col] = np.tile(df2[col].values, len(df1))
Note that tile
just repeats the array elements up to a certain length (here len(df1)
). This is equivalent to
df2[col].values.tolist() * len(df1)
If you need something more performant and clean, have a look at pandas' merge
function.