We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents c1068c2 + 30c1a38 commit bc965c2Copy full SHA for bc965c2
code/nsfg.py
@@ -65,12 +65,17 @@ def CleanFemPreg(df):
65
66
# replace 'not ascertained', 'refused', 'don't know' with NaN
67
na_vals = [97, 98, 99]
68
- df.birthwgt_lb.replace(na_vals, np.nan, inplace=True)
69
- df.birthwgt_oz.replace(na_vals, np.nan, inplace=True)
70
- df.hpagelb.replace(na_vals, np.nan, inplace=True)
71
-
72
- df.babysex.replace([7, 9], np.nan, inplace=True)
73
- df.nbrnaliv.replace([9], np.nan, inplace=True)
+ df.replace(
+ to_replace={
+ "birthwgt_lb": na_vals,
+ "birthwgt_oz": na_vals,
+ "hpagelb": na_vals,
+ "babysex": [7, 9],
74
+ "nbrnaliv": [9],
75
+ },
76
+ value=np.nan,
77
+ inplace=True,
78
+ )
79
80
# birthweight is stored in two columns, lbs and oz.
81
# convert to a single column in lb
0 commit comments