2

I have following code to output a dataFrame:

output = pd.DataFrame({"id":id_test, "hum":y_pred})
output.to_csv("myOutput.csv", index=False)

Then in myOutput.csv, I got hum as the first column, id as the second column. Is there a way to make id the first column instead? Thanks!

1 Answer 1

2

Just reorder the columns:

output.ix[:,['id','hum']].to_csv("myOutput.csv", index=False)

Because you used a dict as the data, the column order is not necessarily the same order as the key creation order in the dict

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.