I am trying to remove ranges of columns in my pandas df. I would prefer to do it in one line but the only method I know is iloc, which doesn't seem to allow multiple references. When I wrote it in separate lines, the columns I don't want remain. Can someone help me with a better way of doing this? Thanks!
import pandas as pd
df = pd.DataFrame({'id': [100,200,300], 'user': ['Bob', 'Jane', 'Alice'], 'income': [50000, 60000, 70000], 'color':['red', 'green', 'blue'], 'state':['GA', 'PA', 'NY'], 'day':['M', 'W', 'Th'], 'color2':['red', 'green', 'blue'], 'state2':['GA', 'PA', 'NY'], 'id2': [100,200,300]})
df.drop(df.iloc[:, 0:2], inplace=True, axis=1)
df.drop(df.iloc[:, 4:5], inplace=True, axis=1)
df.drop(df.iloc[:, 7:9], inplace=True, axis=1)
I'd like the output from the code above to contain columns 'color' and 'color2'