For example, say I have computed two variables A
and B
, both numpy arrays.
Now I would like to make a dataframe out of them, then write to CSV, so that B goes before A. However, when I try:
out_df = pd.DataFrame({'B':B,'A':A})
out_df.head()
I see that column A has been placed to the left of column B. In some analyses, this won't matter, but I specifically want column B first, then column A in the output csv.
How do I tell pd.DataFrame to respect the ordering of the columns as I specify them?