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()
156
156
157
157
If we want to update ` AMZN ` return to 0, you can use the following chain of methods.
158
158
159
+
160
+ Here ` with_columns ` is similar to ` select ` but adds columns to the same ` DataFrame `
161
+
159
162
``` {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
162
165
.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
165
168
)
166
169
df
167
- ```
168
170
169
171
You can check if a ticker code is in the company list
170
172
You can’t perform that action at this time.
0 commit comments