Skip to content

Commit

Permalink
Merge pull request #217 from debnath-d/patch-1
Browse files Browse the repository at this point in the history
Update nsfg.py to fix FutureWarning
  • Loading branch information
AllenDowney authored Jan 23, 2025
2 parents c1068c2 + 30c1a38 commit bc965c2
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions code/nsfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,17 @@ def CleanFemPreg(df):

# replace 'not ascertained', 'refused', 'don't know' with NaN
na_vals = [97, 98, 99]
df.birthwgt_lb.replace(na_vals, np.nan, inplace=True)
df.birthwgt_oz.replace(na_vals, np.nan, inplace=True)
df.hpagelb.replace(na_vals, np.nan, inplace=True)

df.babysex.replace([7, 9], np.nan, inplace=True)
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],
"nbrnaliv": [9],
},
value=np.nan,
inplace=True,
)

# birthweight is stored in two columns, lbs and oz.
# convert to a single column in lb
Expand Down

0 comments on commit bc965c2

Please sign in to comment.