hinkelman
Explorer: sum across series of booleans
I’m new to Elixir (with a background in R) and tinkering with Explorer so I’m probably missing something obvious here.
For this example, we will create a simple dataframe and add a boolean flag.
df = Explorer.DataFrame.new(group: ["A", "B", "B", "C"], value: 1..4)
|> DF.mutate(flag: Explorer.Series.less(value, 3))
I can sum across the boolean series like this…
Explorer.Series.sum(df[:flag])
But when I try to incorporate that in a group_by and summarise
df
|> Explorer.DataFrame.group_by("group")
|> Explorer.DataFrame.summarise(flag_count: sum(flag))
I get this error
#Inspect.Error<
got FunctionClauseError with message:
"""
no function clause matching in Explorer.PolarsBackend.Shared.normalise_dtype/1
"""
while inspecting:
%{
__struct__: Explorer.DataFrame,
data: %Explorer.PolarsBackend.DataFrame{resource: #Reference<0.3997017276.1149894680.178408>},
dtypes: %{"flag_count" => :boolean, "group" => :string},
groups: [],
names: ["group", "flag_count"]
}
Stacktrace:
(explorer 0.5.6) lib/explorer/polars_backend/shared.ex:129: Explorer.PolarsBackend.Shared.normalise_dtype("u32")
(explorer 0.5.6) lib/explorer/polars_backend/shared.ex:75: Explorer.PolarsBackend.Shared.create_series/1
(explorer 0.5.6) lib/explorer/data_frame.ex:3171: Explorer.DataFrame.pull_existing/2
(explorer 0.5.6) lib/explorer/data_frame.ex:342: Explorer.DataFrame.fetch/2
(elixir 1.14.4) lib/access.ex:288: Access.get/3
(explorer 0.5.6) lib/explorer/backend/data_frame.ex:228: anonymous fn/6 in Explorer.Backend.DataFrame.inspect/5
(elixir 1.14.4) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
(explorer 0.5.6) lib/explorer/backend/data_frame.ex:227: Explorer.Backend.DataFrame.inspect/5
What am I missing?
Marked As Solved
kwhite
I’m pretty late here, but I just ran into this myself. Cast flag to an integer before summing:
df
|> Explorer.DataFrame.group_by("group")
|> Explorer.DataFrame.summarise(flag_count: sum(Explorer.Series.cast(flag, :integer))
1
Popular in Questions
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set?
Thanks.
New
In Ruby, I can go:
User.find_by(email: "foobar@email.com").update(email: "hello@email.com")
How can I do something similar in Elixir? ...
New
I have followed this StackOverflow post to install the specific version of Erlang.
And When I am running mix ecto.setup then getting fol...
New
What is most correct way to open, read and parse JSON file with poison?
For example if we have example.json file in root of some projec...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
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
After calling mix ecto.create I get this error:
17:00:32.162 [error] GenServer #PID<0.412.0> terminating
** (Postgrex.Error) FATAL...
New
Other popular topics
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
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
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
New
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...
New
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode.
The solution seems to be, in a hyphena...
New
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
Hi all,
I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I'm trying to use Postg...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New







