Reputation: 4040
Given any pandas dataframe. I want to select columns A, B and F:Z
I have tried to do it df.loc[:, ['A','B','F':'Z']]
but it didn't work.
Please advise how to do this.
Upvotes: 0
Views: 1034
Reputation: 323226
We can do two slice then combine
df.loc[:, ['A','B']].join(df.loc[:,'F':'Z'])
And side solution change all name to position then we can do
df.iloc[:,np.r_[1,2,5:999]]
Upvotes: 4