Managing Data for Influence of Relations with Parents on an Ideal Romantic Relationship

Collins Agubuike
3 min readOct 13, 2020
# importing pandas module
import pandas
import numpy
# any additional libraries would be imported here
# making data frame
data = pandas.read_csv(‘addhealth_pds.csv’, low_memory=False)
#upper-case all DataFrame column names — place afer code for loading data above
data.columns = map(str.upper, data.columns)
# bug fix for display formats to avoid run time errors — put after code for loading data above
pandas.set_option(‘display.float_format’, lambda x:’%f’%x)
print (len(data)) #number of observations (rows)
print (len(data.columns)) # number of variables (columns)
#setting variables you will be working with to numeric
data[‘H1ID1A’] = pandas.to_numeric(data[‘H1ID1A’])
data[‘H1WP2’] = pandas.to_numeric(data[‘H1WP2’])
data[‘H1WP17D’] = pandas.to_numeric(data[‘H1WP17D’])
# recode missing values to python missing (NaN)
data[‘H1ID1A’]=data[‘H1ID1A’].replace([6,8], numpy.nan)
data[‘H1WP2’]=data[‘H1WP2’].replace([6,7,8], numpy.nan)
data[‘H1WP17D’]=data[‘H1WP17D’].replace([6,8], numpy.nan)
#recoding values
recode1 = {2: 0, 1: 1, 9: 9}
data[‘H1ID1A’]= data[‘H1ID1A’].map(recode1)
recode1 = {0: 0, 1: 1, 7: 9, 9: 9}
data[‘H1WP2’]= data[‘H1WP2’].map(recode1)
recode3 = {0: 0, 1: 1, 7: 9}
data[‘H1WP17D’]= data[‘H1WP17D’].map(recode3)
#if you want to include a count of missing add, dropna=False after sort=False
print (‘counts for H1ID1A — going out together in a group, no=0, yes=1, not applicable=9 and number of missing requested’)
ct1 = data[‘H1ID1A’].value_counts(sort=False, dropna=False)
print(ct1)
print (‘percentages for H1ID1A — going out together in a group, no=0, yes=1, not applicable=9 and number of missing requested’)
pt1 = data[‘H1ID1A’].value_counts(sort=False, normalize=True, dropna=False)
print (pt1)
print (‘counts for H1WP2 allowed to make their own decisions about the people they hang around with by their parents, no=0, yes=1, not applicable=9 and number of missing requested’)
ct2= data[‘H1WP2’].value_counts(sort=False, dropna=False)
print (ct2)
print (‘percentages for H1WP2 allowed to make their own decisions about the people they hang around with by their parents, no=0, yes=1, not applicable=9 and number of missing requested’)
pt2 = data[‘H1WP2’].value_counts(sort=False, normalize=True, dropna=False)
print (pt2)
print (‘counts for H1WP17D talked about someone they are dating, or a party they went to with their MOTHER/ADOPTIVE MOTHER/STEPMOTHER/FOSTER MOTHER/etc., no=0, yes=1, not applicable=9 and number of missing requested’)
ct3= data[‘H1WP17D’].value_counts(sort=False, dropna=False)
print (ct3)
print (‘percentages for H1WP17D talked about someone they are dating, or a party they went to with their MOTHER/ADOPTIVE MOTHER/STEPMOTHER/FOSTER MOTHER/etc., no=0, yes=1, not applicable=9 and number of missing requested’)
pt3 = data[‘H1WP17D’].value_counts(sort=False, normalize=True, dropna=False)
print (pt3)

6504
2829

counts for H1ID1A — going out together in a group, no=0, yes=1, not applicable=9 and number of missing requested
1.000000 5396
0.000000 984
nan 119
9.000000 5
Name: H1ID1A, dtype: int64

percentages for H1ID1A — going out together in a group, no=0, yes=1, not applicable=9 and number of missing requested
1.000000 0.829643
0.000000 0.151292
nan 0.018296
9.000000 0.000769
Name: H1ID1A, dtype: float64

counts for H1WP2 allowed to make their own decisions about the people they hang around with by their parents, no=0, yes=1, not applicable=9 and number of missing requested
1.000000 5420
0.000000 942
nan 141
9.000000 1
Name: H1WP2, dtype: int64

percentages for H1WP2 allowed to make their own decisions about the people they hang around with by their parents, no=0, yes=1, not applicable=9 and number of missing requested
1.000000 0.833333
0.000000 0.144834
nan 0.021679
9.000000 0.000154
Name: H1WP2, dtype: float64

counts for H1WP17D talked about someone they are dating, or a party they went to with their MOTHER/ADOPTIVE MOTHER/STEPMOTHER/FOSTER MOTHER/etc., no=0, yes=1, not applicable=9 and number of missing requested
1.000000 2895
0.000000 3228
9.000000 370
nan 11
Name: H1WP17D, dtype: int64

percentages for H1WP17D talked about someone they are dating, or a party they went to with their MOTHER/ADOPTIVE MOTHER/STEPMOTHER/FOSTER MOTHER/etc., no=0, yes=1, not applicable=9 and number of missing requested
1.000000 0.445111
0.000000 0.496310
9.000000 0.056888
nan 0.001691
Name: H1WP17D, dtype: float64

I collapsed the responses for H1ID1A, H1WP2, and H1WP17D. For H1ID1A, the most commonly endorsed response was 1 (82.96%), meaning that most respondents go out together in a group. For H1WP2, the most commonly endorsed response was 1 (83.33%), meaning that over half of the respondents are allowed to make their own decision about people they hang around with by their parents. For H1WP17D, the most commonly endorsed response was 0 (49.63%), meaning that almost half of the respondents do not talk about someone they are dating or a party they went to with their MOTHER/ADOPTIVE MOTHER/STEPMOTHER/FOSTER MOTHER/etc.

--

--