title: KeyError: "Index(column, dtype='object') not in index"
body: <p>I am getting KeyError: &quot;Index(['scanCd'], dtype='object') not in index&quot; error when trying to put the columns of 2 dataframes side by side after concatenating.</p>
  <p>I am not able find out the root cause of the issue can someone help?</p>
  <p>i had already read some of the questions posted but thosse solutions didnt seem to help. my main aim to compare 2 df's and highlight the differences</p>
  <pre><code>{Code:
  
  val ={'lineNum':[10624,11192,15596,15790], 'scanCd':[10,20,30,40], 'brandName':['HP','Dell','Samsung','Lenovo']}
  dft = pd.DataFrame(val, columns= ['lineNum','scanCd','brandName'])
  dfm = dft.copy()
  # change the values of few elements
  dfm.loc[0, 'brandName'] = 'H-P'
  dfm.loc[1, 'brandName'] = 'DELL'
  dfm.loc[2, 'brandName'] = 'SAMSUNG'
  df_all = pd.concat([dft.set_index('scanCd'), dfm.set_index('scanCd')], 
                     axis='columns', keys=['dft', 'dfm'])
  
  df_final = df_all.swaplevel(axis='columns')[dft.columns[0:]]
  
  
  Error:
  Traceback (most recent call last):
  
    File &quot;&lt;ipython-input-318-16965db0a52e&gt;&quot;, line 11, in &lt;module&gt;
      df_final = df_all.swaplevel(axis='columns')[dft.columns[0:]]
  
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py&quot;, line 2986, in __getitem__
      indexer = self.loc._convert_to_indexer(key, axis=1, raise_missing=True)
  
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexing.py&quot;, line 1285, in _convert_to_indexer
      return self._get_listlike_indexer(obj, axis, **kwargs)[1]
  
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexing.py&quot;, line 1075, in _get_listlike_indexer
      indexer, keyarr = ax._convert_listlike_indexer(key, kind=self.name)
  
    File &quot;C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexes\multi.py&quot;, line 2408, in _convert_listlike_indexer
      raise KeyError(&quot;%s not in index&quot; % keyarr[mask])
  
  KeyError: &quot;Index(['scanCd'], dtype='object') not in index&quot;
  }
  </code></pre>