@@ -122,9 +122,8 @@ main = do
122122 ...
123123 let year = (\ (YearMonthDay y _ _) -> y)
124124 print $ df_csv
125- |> D. derive " birth_year" year " birthdate"
126- |> D. deriveFrom ([" weight" , " height" ], D. func (\ (w :: Double ) (h :: Double ) -> w / h ** 2 ))
127- " bmi"
125+ |> D. derive " birth_year" (lift year (D. col @ Date " birthdate" ))
126+ |> D. derive " bmi" ((D. col @ Double " weight" ) / (D. lift2 (**) (D. col @ Double " height" ) (D. lit 2 )))
128127 |> D. select [" name" , " birth_year" , " bmi" ]
129128```
130129
@@ -146,8 +145,8 @@ main = do
146145 let bmi :: Double -> Double -> Double
147146 bmi w h = w / h ** 2
148147 print $ df_csv
149- |> D. derive " birth_year" year " birthdate"
150- |> D. deriveFrom ([ " weight " , " height " ], D. func bmi) " bmi "
148+ |> D. derive " birth_year" (lift year ( D. col @ Date " birthdate" ))
149+ |> D. derive " bmi " (( D. col @ Double " weight " ) / ( D. lift2 (**) ( D. col @ Double " height " ) ( D. lit 2 )))
151150 |> D. select [" name" , " birth_year" , " bmi" ]
152151```
153152
@@ -186,9 +185,8 @@ We instead write this two `applyWithAlias` calls:
186185
187186``` haskell
188187df_csv
189- |> D. derive " weight-5%" (* 0.95 ) " weight"
190- -- Alternatively we can use the `as` function.
191- |> D. as " height-5%" D. apply (* 0.95 ) " height"
188+ |> D. derive " weight-5%" ((col @ Double " weight" ) * (lit 0.95 ))
189+ |> D. derive " height-5%" ((col @ Double " height" ) * (lit 0.95 ))
192190 |> D. select [" name" , " weight-5%" , " height-5%" ]
193191```
194192
@@ -207,7 +205,7 @@ index | name | height-5% | weight-5%
207205However we can make our program shorter by using regular Haskell and folding over the dataframe.
208206
209207``` haskell
210- let reduce name = D. derive (name <> " -5%" ) (* 0.95 ) name
208+ let reduce name = D. derive (name <> " -5%" ) ((col @ Double name) * (lit 0.95 ))
211209df_csv
212210 |> D. fold reduce [" weight" , " height" ]
213211 |> D. select [" name" , " weight-5%" , " height-5%" ]
@@ -324,7 +322,7 @@ print(result)
324322``` haskell
325323decade = (* 10 ) . flip div 10 . year
326324df_csv
327- |> D. derive " decade" decade " birthdate"
325+ |> D. derive " decade" (lift decade (col @ date " birthdate" ))
328326 |> D. groupByAgg D. Count [" decade" ]
329327 |> D. aggregate [(" height" , D. Maximum ), (" weight" , D. Mean )]
330328 |> D. select [" decade" , " sampleSize" , " Mean_weight" , " Maximum_height" ]
0 commit comments