title: How to make prediction on the new data in Pandas DataFrame with some extra columns?
body: <p>I have used random forest classifier to build a model - model works fine I am able to output score as well as probability value on the train and test . </p>
  
  <p>The challenge is :</p>
  
  <ul>
  <li><p>I used 29 variables as features with 1 Target </p></li>
  <li><p>When I score the X_Test it works fine </p></li>
  <li>When I bring in a new data set which has 29 variables and my Unique ID /primary key - model errors out saying its looking for 29 variables</li>
  </ul>
  
  <p><strong>How do I  retain my ID and get prediction for the new file ?</strong></p>
  
  <p>What I tried so far - </p>
  
  <pre><code>data = pd.read_csv('learn2.csv')
  y=data['Target']  # Labels
  
  X=data[[
          'xsixn',    'xssocixtesDegreeOnggy',    'xverxgeeeouseeeoggdIncome',    'BxceeeggorsDegreeOnggy',   'Bggxckorxfricxnxmericxn',  
  'Ceeiggdrenxteeome',    'Coggggege',    'Eggementxry',  'GrxduxteDegree',   'eeigeeSceeoogg',   'eeigeeSceeooggGrxduxte',   'eeouseeeoggdsEst', 
  'MedixneeouseeeoggdIncome', 'NoVeeeicgges', 'Oteeerxsixn',  'OteeersRxces', 'OwnerOccupiedPercent', 'PercentBggueCoggggxrWorkers',
      'PercentWeeiteCoggggxr',    'PopuggxtionEst',   'PopuggxtionPereeouseeeoggd',   'RenterOccupiedPercent',    'RetiredOrDisxbggePersons',
      'TotxggDxytimePopuggxtion', 'TotxggStudentPopuggxtion', 'Unempggoyed',  'VxcxnteeousingPercent',    'Weeite',   'WorkpggxceEstxbggiseements'
  
          ]]
  
  # Import train_test_split function
  from sklearn.model_selection import train_test_split
  
      # Split dataset into training set and test set
      X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2) # 80% training
  
      #Import Random Forest Model
      from sklearn.ensemble import RandomForestClassifier
  
      #Create a Gaussian Classifier
      clf=RandomForestClassifier(n_estimators=100)
  
  
      #Train the model using the training sets y_pred=clf.predict(X_test)
      clf.fit(X_train,y_train)
      y_pred=clf.predict(X_test)
  </code></pre>
  
  <p>Predicting on new file:</p>
  
  <pre><code>data1=pd.read_csv('score.csv')
  y_pred2=clf.predict(data2)
  
  ValueError: Number of features of the model must match the input. Model n_features is 29 and input n_features is 30 
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/eDRWl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eDRWl.png" alt="enter image description here"></a></p>