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’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Hi everyone,
I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
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
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
Hi folks,
Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
New
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
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
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #hex
- #security









