<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Exercise from Think Stats, 2nd Edition (thinkstats2.com)<br>
Allen Downey
Read the female respondent file.
Step1:  Make a PMF of <tt>numkdhh</tt>, the number of children under 18 in the respondent's household.
Step2:  Display the PMF.
Step4:  Define <tt>BiasPmf</tt>.
Step5:  Make a the biased Pmf of children in the household, as observed if you surveyed the children instead of the respondents.
Step6:  Display the actual Pmf and the biased Pmf on the same axes.
Step7:  Compute the means of the two Pmfs.
<ASSISTANT_TASK:>
Python Code:
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt
matplotlib.style.use('ggplot')
import chap01soln
resp = chap01soln.ReadFemResp()
Explanation: Exercise from Think Stats, 2nd Edition (thinkstats2.com)<br>
Allen Downey
Read the female respondent file.
End of explanation
resp_numkdhh = resp.numkdhh
resp_numkdhh_vc = resp_numkdhh.value_counts().sort_index()
print resp_numkdhh_vc
resp_numkdhh_pmf_original = resp_numkdhh_vc / len(resp_numkdhh)
Explanation: Make a PMF of <tt>numkdhh</tt>, the number of children under 18 in the respondent's household.
End of explanation
resp_numkdhh_pmf_original.plot(kind = 'bar', legend = True, label= 'original')
Explanation: Display the PMF.
End of explanation
def BiasPmf(pmf, label=''):
    Returns the Pmf with oversampling proportional to value.
    If pmf is the distribution of true values, the result is the
    distribution that would be seen if values are oversampled in
    proportion to their values; for example, if you ask students
    how big their classes are, large classes are oversampled in
    proportion to their size.
    Args:
      pmf: Pmf object.
      label: string label for the new Pmf.
     Returns:
       Pmf object
    
    new_pmf = pmf.Copy(label=label)
    for x, p in pmf.Items():
        new_pmf.Mult(x, x)
        
    new_pmf.Normalize()
    return new_pmf
Explanation: Define <tt>BiasPmf</tt>.
End of explanation
import pandas as pd
resp_numkdhh_pmf_biased = pd.DataFrame()
biased_list = [ index * row for index, row in resp_numkdhh_pmf_original.iteritems()]
resp_numkdhh_pmf_biased = resp_numkdhh_pmf_biased.append( biased_list)
resp_numkdhh_pmf_biased.columns = ['biased']
resp_numkdhh_pmf_biased.plot(kind = 'bar')
Explanation: Make a the biased Pmf of children in the household, as observed if you surveyed the children instead of the respondents.
End of explanation
resp_numkdhh_pmf_original = pd.DataFrame(resp_numkdhh_pmf_original, columns=['original'])
resp_numkdhh_pmf = resp_numkdhh_pmf_original
resp_numkdhh_pmf['biased'] = resp_numkdhh_pmf_biased.biased
resp_numkdhh_pmf.plot(kind='bar')
Explanation: Display the actual Pmf and the biased Pmf on the same axes.
End of explanation
resp_numkdhh_pmf
resp_numkdhh_pmf_biased.sum()
sum([row * index for index, row in resp_numkdhh_pmf.biased.iteritems()])
Explanation: Compute the means of the two Pmfs.
End of explanation
<END_TASK>