LearningPath
LearningPath

Reputation: 93

Concatenate/Join/Merge two Dataframes with one missing column

I know the issue could have been already asked but I checked them all and I think my case is different (be kind please). So I have 2 datasets, the first one is the test dataset and the second one is the prediction (predicted values, that is why there is no data column) that I have saved in a dataframe. I want to merge both and have a dataframe like the one in the second image I posted. About the date column ... is there any tip/trick I can use here. Thanks

Dataframes output

here my line of code

result = pd.concat([test_df, pred_df], axis=1).reindex(test_df.index)
result

Upvotes: 1

Views: 198

Answers (1)

ProteinGuy
ProteinGuy

Reputation: 1942

The problem is most likely because your dataframes have different indices. Do:

pred_df.index = test_df.index
result = pd.concat([test_df, pred_df], axis=1).reindex(test_df.index)

Upvotes: 1

Related Questions