df = df.iloc[:,0:2] df = df[['column1', 'column2']]
Here is what the above code is Doing:
1. We’re using the .iloc[] method to select the first two columns of the dataframe.
2. We’re using the [] method to select the columns by name.
3. We’re using the .loc[] method to select the columns by name.
4. We’re using the .ix[] method to select the columns by name.
Note that the .iloc[] method is the most efficient way to select columns by position.