简体   繁体   中英

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

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?

Then save to csv like this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM