0

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.

SteveS
  • 3,789
  • 5
  • 30
  • 64

1 Answers1

4

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]]
BENY
  • 317,841
  • 20
  • 164
  • 234