Skip to content
Advertisement

Select multiple ranges of columns in Pandas DataFrame

I have to read several files some in Excel format and some in CSV format. Some of the files have hundreds of columns.

Is there a way to select several ranges of columns without specifying all the column names or positions? For example something like selecting columns 1 -10, 15, 17 and 50-100:

JavaScript

I need to know how to do this both when creating dataframe from Excel files and CSV files and after the data framers created.

Advertisement

Answer

use np.r_

JavaScript

so you can do

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement