title: ValueError: invalid fill value with a <class 'pandas.core.frame.DataFrame'>
body: <p>I am practising on a loan prediction practise problem and trying to fill missing values in my data. I obtained the data from <a href="https://datahack.analyticsvidhya.com/contest/practice-problem-loan-prediction-iii/" rel="nofollow noreferrer">here</a>. To complete this problem I am following this <a href="https://www.analyticsvidhya.com/blog/2016/01/complete-tutorial-learn-data-science-python-scratch-2/" rel="nofollow noreferrer">tutorial</a>.</p>
  
  <p>You can find the entire code (<em>file name model.py</em>) I am using  and the data <a href="https://github.com/Aniruddh-SK/Loan-Prediction-Problem" rel="nofollow noreferrer">here</a> on GitHub. </p>
  
  <p>The DataFrame looks like this:</p>
  
  <pre><code>df[['Loan_ID', 'Self_Employed', 'Education', 'LoanAmount']].head(10)
  Out: 
      Loan_ID Self_Employed     Education  LoanAmount
  0  LP001002            No      Graduate         NaN
  1  LP001003            No      Graduate       128.0
  2  LP001005           Yes      Graduate        66.0
  3  LP001006            No  Not Graduate       120.0
  4  LP001008            No      Graduate       141.0
  5  LP001011           Yes      Graduate       267.0
  6  LP001013            No  Not Graduate        95.0
  7  LP001014            No      Graduate       158.0
  8  LP001018            No      Graduate       168.0
  9  LP001020            No      Graduate       349.0
  </code></pre>
  
  <p><strong>After the last line is executed (corresponds to line 60 in the model.py file)</strong></p>
  
  <pre><code>url = 'https://raw.githubusercontent.com/Aniruddh-SK/Loan-Prediction-Problem/master/train.csv'
  df = pd.read_csv(url) 
  df['LoanAmount'].fillna(df['LoanAmount'].mean(), inplace=True)
  df['Self_Employed'].fillna('No',inplace=True)
  
  table = df.pivot_table(values='LoanAmount', index='Self_Employed' ,columns='Education', aggfunc=np.median)
  # Define function to return value of this pivot_table
  def fage(x):
   return table.loc[x['Self_Employed'],x['Education']]
  # Replace missing values
  df['LoanAmount'].fillna(df[df['LoanAmount'].isnull()].apply(fage, axis=1), inplace=True)
  </code></pre>
  
  <p><strong>I am getting this error</strong> :</p>
  
  <pre><code>ValueError                                Traceback (most recent call last)
  &lt;ipython-input-40-5146e49c2460&gt; in &lt;module&gt;()
  ----&gt; 1 df['LoanAmount'].fillna(df[df['LoanAmount'].isnull()].apply(fage, axis=1), inplace=True)
  
  /usr/local/lib/python2.7/dist-packages/pandas/core/series.pyc in fillna(self, value, method, axis, inplace, limit, downcast, **kwargs)
     2368                                           axis=axis, inplace=inplace,
     2369                                           limit=limit, downcast=downcast,
  -&gt; 2370                                           **kwargs)
     2371 
     2372     @Appender(generic._shared_docs['shift'] % _shared_doc_kwargs)
  
  /usr/local/lib/python2.7/dist-packages/pandas/core/generic.pyc in fillna(self, value, method, axis, inplace, limit, downcast)
     3264                 else:
     3265                     raise ValueError("invalid fill value with a %s" %
  -&gt; 3266                                      type(value))
     3267 
     3268                 new_data = self._data.fillna(value=value, limit=limit,
  
  ValueError: invalid fill value with a &lt;class 'pandas.core.frame.DataFrame'&gt;
  </code></pre>
  
  <p>How do I fill the missing values without getting this error? </p>