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
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
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
can someone please explain to me how Enum.reduce works with maps
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
I have a User schema with a :from_id field set to type :string:
defmodule TweetBot.Repo.Migrations.CreateUsers do
use Ecto.Migration
...
New
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
Sometimes I want to check if the input into a function is not a blank string.
My first approach:
defmodule Example do
def do_stuff(s...
New
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: )
Hello all, this is ...
New
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
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
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
New
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
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
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
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
Hi,
I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
Hi everyone,
One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
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
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum.
...
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







