File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -156,15 +156,17 @@ df.filter(pl.col('company') == 'AMZN').select('daily returns').item()
156156
157157If 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)
166169df
167- ```
168170
169171You can check if a ticker code is in the company list
170172
You can’t perform that action at this time.
0 commit comments