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,164
  • 2
  • 24
  • 43

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
  • 296,997
  • 19
  • 147
  • 204