title: Axis error when dropping specific columns Pandas
body: <p>I have identified specific columns I want to select as my predictors for my model based on some analysis. I have captured those column numbers and stored it in a list. I have roughly 80 columns and want to loop through and drop the columns not in this specific list. X_train is the column in which I want to do this. Here is my code:</p>
  
  <pre><code>cols_selected = [24, 4, 7, 50, 2, 60, 46, 53, 48, 61]
  cols_drop = []
  
  for x in range(len(X_train.columns)):
      if x in cols_selected:
          pass
      else:
          X_train.drop([x])
  </code></pre>
  
  <p>When running this, I am faced with the following error while highlighting the code: X_train.drop([x]):</p>
  
  <blockquote>
    <p>KeyError: '[3] not found in axis'</p>
  </blockquote>
  
  <p>I am sure it is something very simple that I am missing. I tried including the inplace=True or axis=1 statements along with this and all of them had the same error message (while the value inside the [] changed with those error codes).</p>
  
  <p>Any help would be great!</p>
  
  <p>Edit: Here is the addition to get this working:</p>
  
  <pre><code>cols_selected = [24, 4, 7, 50, 2, 60, 46, 53, 48, 61]
  cols_drop = []
  
  for x in range(len(X_train.columns)):
      if x in cols_selected:
          pass
      else:
          cols_drop.append(x)
  
  X_train = X_train.drop(X_train.columns[[cols_drop]], axis=1)    
  </code></pre>