I have a (large) dataframe. How can I select specific columns by position? e.g. columns 1..3, 5, 6
Rather than just drop column4, I am trying to do it in this way because there are a ton of rows in my dataset and I want to select by position:
df=df[df.columns[0:2,4:5]]
but that gives IndexError: too many indices for array
DF input
Col1 Col2 Col3 Col4 Col5 Col6
1 apple tomato pear banana banana
1 apple grape nan banana banana
1 apple nan banana banana banana
1 apple tomato banana banana banana
1 apple tomato banana banana banana
1 apple tomato banana banana banana
1 avacado tomato banana banana banana
1 toast tomato banana banana banana
1 grape tomato egg banana banana
DF output - desired
Col1 Col2 Col3 Col5 Col6
1 apple tomato banana banana
1 apple grape banana banana
1 apple nan banana banana
1 apple tomato banana banana
1 apple tomato banana banana
1 apple tomato banana banana
1 avacado tomato banana banana
1 toast tomato banana banana
1 grape tomato banana banana