daru

https://github.com/sciruby/daru

Ruby

Data Analysis in RUby

Daru::DataFrame#group_by

Group elements by vector to perform operations on them. Returns a
Daru::Core::GroupBy object.See the Daru::Core::GroupBy docs for a detailed
list of possible operations.

== Arguments

* vectors - An Array contatining names of vectors to group by.

== Usage

  df = Daru::DataFrame.new({
    a: %w{foo bar foo bar   foo bar foo foo},
    b: %w{one one two three two two one three},
    c:   [1  ,2  ,3  ,1    ,3  ,6  ,3  ,8],
    d:   [11 ,22 ,33 ,44   ,55 ,66 ,77 ,88]
  })
  df.group_by([:a,:b,:c]).groups
  #=> {["bar", "one", 2]=>[1],
  # ["bar", "three", 1]=>[3],
  # ["bar", "two", 6]=>[5],
  # ["foo", "one", 1]=>[0],
  # ["foo", "one", 3]=>[6],
  # ["foo", "three", 8]=>[7],
  # ["foo", "two", 3]=>[2, 4]}

Source | Google | Stack overflow

Edit

git clone [email protected]:sciruby/daru.git

cd daru

open lib/daru/dataframe.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-Daru--DataFrame-group_by-for-pr


# Commit to git

git add lib/daru/dataframe.rbgit commit -m "better docs for Daru::DataFrame#group_by"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-Daru--DataFrame-group_by-for-pr

hub pull-request


# Celebrate!