boiserunner

boiserunner

Explorer.DataFrame mutation help

I have an Explorer.DataFrame, like so.

df = DataFrame.new(
  goal: Enum.to_list(60..1) |> Series.from_list()
)

df = DataFrame.put(df, :day_of_week, Explorer.Series.transform(Series.subtract(df["day"], 1), &get_day_of_week/1))

Simple enough. But now I need to create another column that relies on the others. Something like — if the day of week is 1, multiple the goal column value by 3, otherwise by 6.

I’m oversimplifying my use case, but it seems like when I need to do conditional logic with multiple columns, I can’t quite finesse the code.

Am I stuck with converting to a list, doing work, and then back to a series?

Marked As Solved

al2o3cr

al2o3cr

You could use Series.select to implement what you’re describing:

Series.select(
  Series.equal(df["day_of_week"], 1)
  Series.multiply(df["goal"], 3),
  Series.multiply(df["goal"], 6)
)

Last Post!

boiserunner

boiserunner

Thank you!

Where Next?

Popular in Questions Top

dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31525 112
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49134 226
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

We're in Beta

About us Mission Statement