Home > Back-end >  Append a single Column dataframe to another DataFrame in the last
Append a single Column dataframe to another DataFrame in the last

Time:11-24

I have two dataframes:

Actual_Values
0   0.60
1   0.60
2   0.60
3   0.60
4   0.60


Predicted_Values
0   0.60
1   0.60
2   0.60

and I want a something like this:

Actual_Values   Predicted_Values
0   0.60    NaN
1   0.60    NaN
2   0.60    0.6
3   0.60    0.6
4   0.60    0.6

I have tried pandas' join, merge, concat, but none works.

CodePudding user response:

Try with assign the new index

df2.index=df1.index[-len(df2):]
out = df1.join(df2)
Out[283]: 
   Actual_Values  Predicted_Values
0            0.6               NaN
1            0.6               NaN
2            0.6               0.6
3            0.6               0.6
4            0.6               0.6
  • Related