vishal-h
Explorer.DataFrame.group_by slice help
require Explorer.DataFrame, as: DF
df = Explorer.DataFrame.new(%{id: [1, 2, 3, 4], name: ["Raj", "Tara", "Bobby", "Anita"], gender: ["m", "f", "m", "f"]})
grouped = df |> DF.group_by("gender")
grouped |> DF.table gives
+---------------------------------------------+
| Explorer DataFrame: [rows: 4, columns: 3] |
+--------------+---------------+--------------+
| gender | id | name |
| <string> | <integer> | <string> |
+==============+===============+==============+
| m | 1 | Raj |
+--------------+---------------+--------------+
| m | 3 | Bobby |
+--------------+---------------+--------------+
| f | 2 | Tara |
+--------------+---------------+--------------+
| f | 4 | Anita |
+--------------+---------------+--------------+
grouped |> DF.slice(0…0) |> DF.table gives
+---------------------------------------------+
| Explorer DataFrame: [rows: 2, columns: 3] |
+--------------+---------------+--------------+
| gender | id | name |
| <string> | <integer> | <string> |
+==============+===============+==============+
| m | 1 | Raj |
+--------------+---------------+--------------+
| f | 2 | Tara |
+--------------+---------------+--------------+
Since it’s grouped on gender I was expecting
+---------------------------------------------+
| Explorer DataFrame: [rows: 2, columns: 3] |
+--------------+---------------+--------------+
| gender | id | name |
| <string> | <integer> | <string> |
+==============+===============+==============+
| m | 1 | Raj |
+--------------+---------------+--------------+
| m | 3 | Bobby |
+--------------+---------------+--------------+
What am I missing?
Marked As Solved
josevalim
Creator of Elixir
When you group in Explorer, you can think you divide your dataframe into several groups, and the operations often apply to the groups individually and then are put together. In this case, you are slicing each group. So you are getting one entry from each gender.
Popular in Questions
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
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
Hello, I have map which I want to convert it to string like this:
the map:
%{last_name: "tavakkoli", name: "shahryar"}
the string I ne...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
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
I will often find my self writing things similar to:
case some_value do
nil -> something()
"" -> something()
_ -> someth...
New
I have a super simple question about elixir - how would I take a file like this
foo bar baz
and output a new file that enumerates th...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
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
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
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
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
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
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
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
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
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
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
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







