Is there a way to preserve the order of the columns in a csv file when read and the write with Python Pandas? For example, in this code
import pandas as pd
Another workaround is to do this:
import pandas as pd data = pd.read_csv(filename) data2 = df[['A','B','C']] #put 'A' 'B' 'C' in the desired order data2.to_csv(filename)