I have a csv file with 50 columns of data. I am using Pandas read_csv function to pull in a subset of these columns, using the usecols parameter to choose the ones I want:<
Just piggybacking off this question here (hi from 2018).
I discovered the same problem with my pandas read_csv and wanted to figure out a way to take the [col_reorder] using column header strings. It's as simple as defining an array of strings to use.
pd.read_csv(filepath, index_col=False, usecols=cols_to_use)[index_strings]
you can reuse the same cols_to_use
list for selecting columns in desired order:
df_ret = pd.read_csv(filepath, index_col=False, usecols=cols_to_use)[cols_to_use]