title: KeyError: Not in index, using a keys generated from a Pandas dataframe on itself
body: <p>I have two columns in a <code>Pandas</code> <code>DataFrame</code> that has <code>datetime</code> as its index. The two column contain data measuring the same parameter but neither column is complete (some row have no data at all, some rows have data in both column and other data on in column 'a' or 'b').</p>
  
  <p>I've written the following code to find gaps in columns, generate a list of indices of dates where these gaps appear and use this list to find and replace missing data. However I get a <code>KeyError: Not in index</code> on line 3, which I don't understand because the keys I'm using to index came from the <code>DataFrame</code> itself. Could somebody explain why this is happening and what I can do to fix it? Here's the code:</p>
  
  <pre><code>def merge_func(df):
      null_index = df[(df['DOC_mg/L'].isnull() == False) &amp; (df['TOC_mg/L'].isnull() == True)].index
      df['TOC_mg/L'][null_index] = df[null_index]['DOC_mg/L']
      notnull_index = df[(df['DOC_mg/L'].isnull() == True) &amp; (df['TOC_mg/L'].isnull() == False)].index
      df['DOC_mg/L'][notnull_index] = df[notnull_index]['TOC_mg/L']
  
      df.insert(len(df.columns), 'Mean_mg/L', 0.0)
      df['Mean_mg/L'] = (df['DOC_mg/L'] + df['TOC_mg/L']) / 2
      return df
  
  merge_func(sve)
  </code></pre>