How to combine rows with different row indexes.
Please let me know what I should do in the following cases.
DatDataFrame1
Multiple date data and features (2001~)
↓
②Convert DataFrame1 to matrix
To use scikit-learn's machine learning model to make a payment
"Only the feature amount from ""2008"" is extracted, and after matrixization, it is applied to the prediction."
↓
③Combining Date and Predict Results
For ease of viewing, I would like to combine the date of DataFrame1 with the result of the predict (matrix).
While the former has a row index dumped on the original DataFrame,
The latter has a row index starting at zero, so
When combined, the lines shift (only the dates come together and lumped down)
What should I do?Also, the binding is done below.
i_date=df['date']
i_pred=pd.Series(gr.predict(X_test))
df2=pd.concat([i_date, i_pred], axis=1)
*df corresponds to the original DataFrame1.Gr is the machine learning model.
X_test is a matrix of features extracted from the original DataFrame1.
How to set the index of the original df to the index of i_pred
i_date=df['date']
i_pred=pd.Series (gr.predict(X_test), index=df.index)
df2=pd.concat([i_date, i_pred], axis=1)
How to re-send the index value on the i_date side from 0
i_date=df['date'].reset_index(drop=True)
i_pred=pd.Series(gr.predict(X_test))
df2=pd.concat([i_date, i_pred], axis=1)
How about around here?
© 2024 OneMinuteCode. All rights reserved.