Skip to content

Support bins: option in value_counts #12

@mrkn

Description

@mrkn

bins: should be an integer or an array of integers.

If an integer bins is given, the values are grouped into half-open bins.

If an array of integers is given as bins, the array elements represent the lower limits of each bin. The array must increase monotonically.

Example

>> [1, 2, 1, 1, 3, 4, 4, 5, 2, 6].value_counts(bins: 4)
{ (1.0 ... 2.25) => 5,
  (2.25 ... 3.5) => 1,
  (3.5 ... 4.75) => 2,
  (4.75 ... 6.005) => 2 }

>> [1, 2, 1, 1, 3, 4, 4, 5, 2, 6].value_counts(bins: [1, 2, 3, 4, 5, 6], dropna: false)
{ (1 ... 2) => 3,
  (2 ... 3) => 2,
  (3 ... 4) => 1,
  (4 ... 5) => 2,
  (5 ... 6) => 1,
  nil => 1 }

>> [1, 2, 1, 1, 3, 4, 4, 5, 2, 6].value_counts(bins: [1, 3, 5, 7])
{ (1 ... 3) => 5,
  (3 ... 5) => 3,
  (5 ... 7) => 2 }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions