title: Pandas Dataframe: Replacing NaN with row average
body: <p>I am  trying to learn pandas but I have been puzzled with the following. I want to replace NaNs in a DataFrame with the row average. Hence something like <code>df.fillna(df.mean(axis=1))</code> should work but for some reason it fails for me. Am I missing anything, is there something wrong with what I'm doing? Is it because its not implemented? see <a href="https://stackoverflow.com/questions/29478641/how-to-replace-nan-with-sum-of-the-row-in-pandas-datatframe">link here</a></p>
  <pre><code>import pandas as pd
  import numpy as np
  ​
  pd.__version__
  Out[44]:
  '0.15.2'
  
  In [45]:
  df = pd.DataFrame()
  df['c1'] = [1, 2, 3]
  df['c2'] = [4, 5, 6]
  df['c3'] = [7, np.nan, 9]
  df
  
  Out[45]:
      c1  c2  c3
  0   1   4   7
  1   2   5   NaN
  2   3   6   9
  
  In [46]:  
  df.fillna(df.mean(axis=1)) 
  
  Out[46]:
      c1  c2  c3
  0   1   4   7
  1   2   5   NaN
  2   3   6   9
  </code></pre>
  <p>However something like this looks to work fine</p>
  <pre><code>df.fillna(df.mean(axis=0)) 
  
  Out[47]:
      c1  c2  c3
  0   1   4   7
  1   2   5   8
  2   3   6   9
  </code></pre>