Skip to content

Commit 77982bf

Browse files
mmckyHumphreyYang
andauthored
Update lectures/polars.md
Co-authored-by: Humphrey Yang <[email protected]>
1 parent f73ead1 commit 77982bf

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

lectures/polars.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,12 @@ The ability to make changes in dataframes is important to generate a clean datas
369369
**1.** We can use conditional logic to "keep" certain values and replace others
370370

371371
```{code-cell} ipython3
372-
df.with_columns( # add data column to the same dataframe
373-
pl.when(pl.col('POP') >= 20000) # when population is greater than 20,000
372+
df.with_columns(
373+
pl.when(pl.col('POP') >= 20000) # when population >= 20000
374374
.then(pl.col('POP')) # keep the population value
375-
.otherwise(None) # otherwise set the value to null
376-
.alias('POP_filtered') # save results in column POP_filtered
377-
).select(['country', 'POP', 'POP_filtered']) # select the columns of interest
375+
.otherwise(None) # otherwise set to null
376+
.alias('POP_filtered') # save results in POP_filtered
377+
).select(['country', 'POP', 'POP_filtered']) # select the columns
378378
```
379379

380380
**2.** We can modify specific values based on conditions

0 commit comments

Comments
 (0)