title: Pandas - Replacing Nulls with the most frequent value from groups
body: <p>I have a dataset containing the following columns: </p>
  
  <pre><code>['sex', 'age', 'relationship_status]
  </code></pre>
  
  <p>There are some NaN values in 'relationship_status' column and I want to replace them with the most common value in each group based on age and gender. </p>
  
  <p>I know how to groupby and count the values:</p>
  
  <pre class="lang-py prettyprint-override"><code>df2.groupby(['age','sex'])['relationship_status'].value_counts()
  </code></pre>
  
  <p>and it returns:</p>
  
  <pre><code>age   sex     relationship_status
  17.0  female  Married with kids       1
  18.0  female  In relationship         5
                Married                 4
                Single                  4
                Married with kids       2
        male    In relationship         9
                Single                  5
                Married                 4
                Married with kids       4
                Divorced                3
  .
  .
  .
  
  86.0  female  In relationship         1
  92.0  male    Married                 1
  97.0  male    In relationship         1
  </code></pre>
  
  <p>So again, what I need to achieve is that whenever "relationship_status" is empty I need the program to replace it with the most frequent value based on persons age and gender.</p>
  
  <p>Can anyone suggest how can I do it?</p>
  
  <p>Kind regards.</p>