Skip to content

Commit 7555f8c

Browse files
20240414 - fix warning
1 parent 5570993 commit 7555f8c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

dataManagement.qmd

+6-2
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,13 @@ mydata.loc[mydata['sex'] == "female", 'oldVar2'] = 0
369369
Recode multiple variables:
370370

371371
```{python}
372-
mydata.loc[:, 'survived':'pclass'] = mydata.loc[:, 'survived':'pclass'].map(lambda x: 'Yes' if x == 1 else 'No')
372+
columns_to_recode = ['survived', 'pclass']
373373
374-
mydata.loc[:, 'survived':'pclass'] = mydata.loc[:, 'survived':'pclass'].map(lambda x: 1 if x in [0, 1] else 2)
374+
for col in columns_to_recode:
375+
mydata[col] = mydata[col].map({1: 'Yes', 0: 'No'})
376+
377+
for col in columns_to_recode:
378+
mydata[col] = mydata[col].map(lambda x: 1 if x in [0, 1] else 2)
375379
```
376380

377381
# Rename Variables {#renameVars}

0 commit comments

Comments
 (0)