I have two pandas dataframes, lets call them df1 and df2. df1 doesn't have df2's columns, I'm trying to set the values of df2 in df1 in a specific row, (df2 is generated when I loop over df1 so this is why I have the row index)
Basically trying to do something like this:
df1 = pd.DataFrame({"col1": [1, 2], "col2": [3, 4]})
df2 = pd.DataFrame({"col3": [42], "col4": [83]})
row_index = 1
df1[df2.columns][row_index] = df2
Expected result is:
col1 col2 col3 col4
0 1 3 NaN NaN
1 2 4 42 83
I tried all of the following and nothing is working:
df1 = pd.concat([df1, df2], axis=1)
df1 = pd.concat([df1.iloc[row_index], df2], axis=1)
df1[df2.columns] = df2
df1[df2.columns].iloc[row_index] = df2