I am reading a CSV file into pandas:
df = pd.read_csv('file.csv')
However, I notice that column order is not preserved. I can't find anything in the docs that explain how to keep the column order when reading in the CSV file.
I am reading a CSV file into pandas:
df = pd.read_csv('file.csv')
However, I notice that column order is not preserved. I can't find anything in the docs that explain how to keep the column order when reading in the CSV file.
you can pass list of the columns with the order you would like them to have:
columns = ['a', 'x', 'b', 'y']
df = pd.read_csv('file.csv', usecols=columns)