title: How do I combine/ensemble results of 3 machine learning models stored in 3 dataframes and output 1 dataframe with results agreed by majority?
body: <p>I am currently participating in an online hackathon. All the top entries are within 1% of each other. So I decided to run 3 different models instead of a single best performing one, i.e. ensemble learning, tuned hyperparameters on each one of them and then combine results of all three to get a better model. I've combined results of all three in a dataframe, it's df.head() is as below:</p>
  
  <pre><code>index | building_id | rf_damage_grade | xg_damage_grade | lr_damage_grade   | damage_grade
  
  0   a3380c4f75  Grade 4 Grade 2 Grade 3 Grade 4
  
  1   a338a4e653  Grade 5 Grade 5 Grade 5 Grade 5
  
  2   a338a4e6b7  Grade 5 Grade 5 Grade 5 Grade 5
  
  3   a33a6eaa3a  Grade 3 Grade 2 Grade 4 Grade 3
  
  4   a33b073ff6  Grade 5 Grade 5 Grade 5 Grade 5
  </code></pre>
  
  <p>So 'rf_damage_grade' is the column of my best classifier. It gives around 74% accuracy, other two give 68% and 58% respectively. In final output i want, if  'xg_damage_grade' and 'lr_damage_grade' both agree on one value the final output 'damage_grade' gets changed to that value, otherwise it remains equal to the output of 'rf_damage_grade'. There are more than 400k rows in the data and and every time I rerun my model it is taking around an hour to do this on my Early 2015 MBP. Following is the code i've written: </p>
  
  <pre><code>for i in range(len(final)):
      if final.iloc[i,2]==final.iloc[i,3]:
          final.iloc[i,4]=final.iloc[i,2]
          if final.iloc[i,3]!=final.iloc[i,1]:
              count+=1
      else:
          continue
  </code></pre>
  
  <p>What can I do to make it more efficient? Is there any inbuilt function in sklearn to do this sort of thing?</p>