0

How do I remove columns starting from a certain index to another, I need to remove columns from 1950 to 2004?

I tried running this but it didn’t work

test = df.drop(df.iloc[:, 1:55],  axis = 1)
sushanth
  • 8,114
  • 3
  • 15
  • 27

1 Answers1

0

Assuming the column names are integers:

test = df.drop(list(range(1950,2005)), axis=1, errors='ignore')

For strings:

test = df.drop(list(map(str, range(1950,2005))), axis=1, errors='ignore')
mozway
  • 81,317
  • 8
  • 19
  • 49