How can I add a column for my predicted results in a Pandas DataFrame then save as a CSV?

Viewed 50

I'm using sklearn if it matters, but I have:

regressor = RandomForestRegressor(
    n_estimators=10, random_state=0, verbose=1, n_jobs=-1)
regressor.fit(X_train, np.ravel(y_train))
y_pred = regressor.predict(X_test)

My y_pred has shape: (3000,)

I want to add that column back to X_test with a header of job_performance and then finally save as a CSV. Can anyone help with this?

1 Answers

Then save to csv like this

X_test['job_perf'] = y_pred
X_test.to_csv('filename.csv')
Related