title: Error"Can only compare identically-labeled Series objects" and sort_index
body: <p>I have two dataframes <code>df1</code> <code>df2</code>with the same numbers of rows and columns and variables, and I'm trying to compare the boolean variable <code>choice</code> in the two dataframes. Then use <code>if/else</code> to manipulate the data. But something seems wrong when I try to compare the boolean var. </p>
  
  <p>Here are my dataframes sample and codes:</p>
  
  <pre><code>#df1
  v_100     choice #boolean
  7          True
  0          True
  7          False
  2          True
  
  #df2
  v_100     choice #boolean
  1          False
  2          True
  74         True
  6          True
  
  def lastTwoTrials_outcome():
       df1 = df.iloc[5::6, :] #df1 and df2 are extracted from the same dataframe first
       df2 = df.iloc[4::6, :]
  
       if df1['choice'] != df2['choice']:  # if "choice" is different in the two dataframes
           df1['v_100'] = (df1['choice'] + df2['choice']) * 0.5
  </code></pre>
  
  <p>Here's the error:</p>
  
  <pre><code>if df1['choice'] != df2['choice']:
  File "path", line 818, in wrapper
  raise ValueError(msg)
  ValueError: Can only compare identically-labeled Series objects
  </code></pre>
  
  <p>I found the same error <a href="https://stackoverflow.com/questions/18548370/pandas-can-only-compare-identically-labeled-dataframe-objects-error">here</a>, and an answer suggests to <code>sort_index</code> first, but I don't really understand why though? Can anyone explain more in detail please (if that's the correct solution)?  </p>
  
  <p>Thanks!</p>