Skip to content

Commit 4fdd052

Browse files
mmckyHumphreyYang
andauthored
Update lectures/polars.md
Co-authored-by: Humphrey Yang <[email protected]>
1 parent 05e0523 commit 4fdd052

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lectures/polars.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,17 @@ df.filter(pl.col('company') == 'AMZN').select('daily returns').item()
156156

157157
If we want to update `AMZN` return to 0, you can use the following chain of methods.
158158

159+
160+
Here `with_columns` is similar to `select` but adds columns to the same `DataFrame`
161+
159162
```{code-cell} ipython3
160-
df = df.with_columns( # with_columns is similar to select but adds columns to the same DataFrame
161-
pl.when(pl.col('company') == 'AMZN') # filter for rows relating to AMZN in company column
163+
df = df.with_columns(
164+
pl.when(pl.col('company') == 'AMZN') # filter for AMZN in company column
162165
.then(0) # set values to 0
163-
.otherwise(pl.col('daily returns')) # otherwise keep the value in daily returns column
164-
.alias('daily returns') # assign back to the daily returns column
166+
.otherwise(pl.col('daily returns')) # otherwise keep the original value
167+
.alias('daily returns') # assign back to the column
165168
)
166169
df
167-
```
168170
169171
You can check if a ticker code is in the company list
170172

0 commit comments

Comments
 (0)