Class: Polars::GroupBy
- Inherits:
-
Object
- Object
- Polars::GroupBy
- Defined in:
- lib/polars/group_by.rb
Overview
Starts a new GroupBy operation.
Instance Method Summary collapse
-
#agg(aggs) ⇒ DataFrame
Use multiple aggregations on columns.
-
#agg_list ⇒ DataFrame
Aggregate the groups into Series.
-
#count ⇒ DataFrame
Count the number of values in each group.
-
#first ⇒ DataFrame
Aggregate the first values in the group.
-
#head(n = 5) ⇒ DataFrame
Get the first
n
rows of each group. -
#last ⇒ DataFrame
Aggregate the last values in the group.
-
#max ⇒ DataFrame
Reduce the groups to the maximal value.
-
#mean ⇒ DataFrame
Reduce the groups to the mean values.
-
#median ⇒ DataFrame
Return the median per group.
-
#min ⇒ DataFrame
Reduce the groups to the minimal value.
-
#n_unique ⇒ DataFrame
Count the unique values per group.
-
#quantile(quantile, interpolation: "nearest") ⇒ DataFrame
Compute the quantile per group.
-
#sum ⇒ DataFrame
Reduce the groups to the sum.
-
#tail(n = 5) ⇒ DataFrame
Get the last
n
rows of each group.
Instance Method Details
#agg(aggs) ⇒ DataFrame
Use multiple aggregations on columns.
This can be combined with complete lazy API and is considered idiomatic polars.
89 90 91 92 93 94 95 96 |
# File 'lib/polars/group_by.rb', line 89 def agg(aggs) df = Utils.wrap_df(_df) .lazy .groupby(by, maintain_order: maintain_order) .agg(aggs) .collect(no_optimization: true, string_cache: false) _dataframe_class._from_rbdf(df._df) end |
#agg_list ⇒ DataFrame
Aggregate the groups into Series.
554 555 556 |
# File 'lib/polars/group_by.rb', line 554 def agg_list agg(Polars.all.list) end |
#count ⇒ DataFrame
Count the number of values in each group.
410 411 412 |
# File 'lib/polars/group_by.rb', line 410 def count agg(Polars.count) end |
#first ⇒ DataFrame
Aggregate the first values in the group.
255 256 257 |
# File 'lib/polars/group_by.rb', line 255 def first agg(Polars.all.first) end |
#head(n = 5) ⇒ DataFrame
Get the first n
rows of each group.
151 152 153 154 155 156 157 158 159 160 |
# File 'lib/polars/group_by.rb', line 151 def head(n = 5) df = ( Utils.wrap_df(_df) .lazy .groupby(by, maintain_order: maintain_order) .head(n) .collect(no_optimization: true, string_cache: false) ) _dataframe_class._from_rbdf(df._df) end |
#last ⇒ DataFrame
Aggregate the last values in the group.
286 287 288 |
# File 'lib/polars/group_by.rb', line 286 def last agg(Polars.all.last) end |
#max ⇒ DataFrame
Reduce the groups to the maximal value.
379 380 381 |
# File 'lib/polars/group_by.rb', line 379 def max agg(Polars.all.max) end |
#mean ⇒ DataFrame
Reduce the groups to the mean values.
441 442 443 |
# File 'lib/polars/group_by.rb', line 441 def mean agg(Polars.all.mean) end |
#median ⇒ DataFrame
Return the median per group.
532 533 534 |
# File 'lib/polars/group_by.rb', line 532 def median agg(Polars.all.median) end |
#min ⇒ DataFrame
Reduce the groups to the minimal value.
348 349 350 |
# File 'lib/polars/group_by.rb', line 348 def min agg(Polars.all.min) end |
#n_unique ⇒ DataFrame
Count the unique values per group.
469 470 471 |
# File 'lib/polars/group_by.rb', line 469 def n_unique agg(Polars.all.n_unique) end |
#quantile(quantile, interpolation: "nearest") ⇒ DataFrame
Compute the quantile per group.
504 505 506 |
# File 'lib/polars/group_by.rb', line 504 def quantile(quantile, interpolation: "nearest") agg(Polars.all.quantile(quantile, interpolation: interpolation)) end |
#sum ⇒ DataFrame
Reduce the groups to the sum.
317 318 319 |
# File 'lib/polars/group_by.rb', line 317 def sum agg(Polars.all.sum) end |
#tail(n = 5) ⇒ DataFrame
Get the last n
rows of each group.
215 216 217 218 219 220 221 222 223 224 |
# File 'lib/polars/group_by.rb', line 215 def tail(n = 5) df = ( Utils.wrap_df(_df) .lazy .groupby(by, maintain_order: maintain_order) .tail(n) .collect(no_optimization: true, string_cache: false) ) _dataframe_class._from_rbdf(df._df) end |