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

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
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
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New

We're in Beta

About us Mission Statement