What is the Pandas idiom for attaching the results of a prediction to the dataframe on which the prediction was made.
For example, if I have something like (where qualityTrain
is the result of a stats models
fit
)
qualityTrain = quality_data[some_selection_criterion]
pred1 = QualityLog.predict(qualityTrain)
qualityTrain = pd.concat([qualityTrain, pd.DataFrame(pred1, columns=['Pred1'])], axis=1)
the 'Pred1' values are not aligned correctly with the rest of qualityTrain
. If I modify the last line so to reads
...pd.DataFrame(pred1, columns=['Pred1'], index=qualityTrain.index)...
I get the results I expect.
Is there a better idiom for attaching results to a dataframe where the dataframe's may have an arbitrary index?