百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

rover

> 编程语言
开源

适用于 Ruby 的简单、强大的数据框架

386 stars0 点赞4 次浏览
访问官网GitHub

工具介绍

适用于 Ruby 的简单、强大的数据框架

Rover

Simple, powerful data frames for Ruby

:mountain: Designed for data exploration and machine learning, and powered by numo-narray-alt

:evergreen_tree: Uses Vega for visualization

Installation

Add this line to your application’s Gemfile:

ruby
gem "rover-df"

Intro

A data frame is an in-memory table. It’s a useful data structure for data analysis and machine learning. It uses columnar storage for fast operations on columns.

Creating Data Frames

From an array

ruby
Rover::DataFrame.new([
  {a: 1, b: "one"},
  {a: 2, b: "two"},
  {a: 3, b: "three"}
])

From a hash

ruby
Rover::DataFrame.new({
  a: [1, 2, 3],
  b: ["one", "two", "three"]
})

From Active Record

ruby
Rover::DataFrame.new(User.all)

From a CSV

ruby
Rover.read_csv("file.csv")
# or
Rover.parse_csv("CSV,data,string")

From Parquet (requires the red-parquet gem)

ruby
Rover.read_parquet("file.parquet")
# or
Rover.parse_parquet("PAR1...")

Attributes

Get number of rows

ruby
df.count

Get column names

ruby
df.keys

Check if a column exists

ruby
df.include?(name)

Selecting Data

Select a column

ruby
df[:a]

Select multiple columns

ruby
df[[:a, :b]]

Select first rows

ruby
df.head
# or
df.first(5)

Select last rows

ruby
df.tail
# or
df.last(5)

Select rows by index

ruby
df[1]
# or
df[1..3]
# or
df[[1, 4, 5]]

Iterate over rows

ruby
df.each_row { |row| ... }

Iterate over a column

ruby
df[:a].each { |item| ... }
# or
df[:a].each_with_index { |item, index| ... }

Filtering

Filter on a condition

ruby
df[df[:a] == 100]
df[df[:a] != 100]
df[df[:a] > 100]
df[df[:a] >= 100]
df[df[:a]  100) & (df[:b] == "one")] # and
df[(df[:a] > 100) | (df[:b] == "one")] # or
df[(df[:a] > 100) ^ (df[:b] == "one")] # xor

Operations

Basic operations

ruby
df[:a] + 5
df[:a] - 5
df[:a] * 5
df[:a] / 5
df[:a] % 5
df[:a] ** 2
df[:a].sqrt
df[:a].cbrt
df[:a].abs

Rounding

ruby
df[:a].round
df[:a].ceil
df[:a].floor

Logarithm

ruby
df[:a].ln # or log
df[:a].log(5)
df[:a].log10
df[:a].log2

Exponentiation

ruby
df[:a].exp
df[:a].exp2

Trigonometric functions

ruby
df[:a].sin
df[:a].cos
df[:a].tan
df[:a].asin
df[:a].acos
df[:a].atan

Hyperbolic functions

ruby
df[:a].sinh
df[:a].cosh
df[:a].tanh
df[:a].asinh
df[:a].acosh
df[:a].atanh

Error function

ruby
df[:a].erf
df[:a].erfc

Summary statistics

ruby
df[:a].count
df[:a].sum
df[:a].mean
df[:a].median
df[:a].percentile(90)
df[:a].min
df[:a].max
df[:a].std
df[:a].var

Count occurrences

ruby
df[:a].tally

Cross tabulation

ruby
df[:a].crosstab(df[:b])

Grouping

Group

ruby
df.group(:a).count

Works with all summary statistics

ruby
df.group(:a).max(:b)

Multiple groups

ruby
df.group(:a, :b).count

Visualization

Add Vega to your application’s Gemfile:

ruby
gem "vega"

And use:

ruby
df.plot(:a, :b)

Specify the chart type (line, pie, column, bar, area, or scatter)

ruby
df.plot(:a, :b, type: "pie")

Group data

ruby
df.plot(:a, :b, group: :c)

Stacked columns or bars

ruby
df.plot(:a, :b, group: :c, stacked: true)

Updating Data

Add a new column

ruby
df[:a] = 1
# or
df[:a] = [1, 2, 3]

Update a single element

ruby
df[:a][0] = 100

Update multiple elements

ruby
df[:a][0..2] = 1
# or
df[:a][0..2] = [1, 2, 3]

Update all elements

ruby
df[:a] = df[:a].map { |v| v.gsub("a", "b") }
# or
df[:a].map! { |v| v.gsub("a", "b") }

Update elements matching a condition

ruby
df[:a][df[:a] > 100] = 0

Clamp

ruby
df[:a].clamp!(0, 100)

Delete columns

ruby
df.delete(:a)
# or
df.except!(:a, :b)

Rename columns

ruby
df.rename(a: :new_a, b: :new_b)
# or
df[:new_a] = df.delete(:a)

Sort rows

ruby
df.sort_by! { |r| r[:a] }

Clear all data

ruby
df.clear

Combining Data Frames

Add rows

ruby
df.concat(other_df)

Add columns

ruby
df.merge!(other_df)

Inner join

ruby
df.inner_join(other_df)
# or
df.inner_join(other_df, on: :a)
# or
df.inner_join(other_df, on: [:a, :b])
# or
df.inner_join(other_df, on: {df_col: :other_df_col})

Left join

ruby
df.left_join(other_df)

Encoding

One-hot encoding

ruby
df.one_hot

Drop a variable in each category to avoid the dummy variable trap

ruby
df.one_hot(drop: true)

Conversion

Array of hashes

ruby
df.to_a

Hash of arrays

ruby
df.to_h

Numo array

ruby
df.to_numo

CSV

ruby
df.to_csv

Parquet (requires the red-parquet gem)

ruby
df.to_parquet

Types

You can specify column types when creating a data frame

ruby
Rover::DataFrame.new(data, types: {"a" => :int64, "b" => :float64})

Or

ruby
Rover.read_csv("data.csv", types: {"a" => :int64, "b" => :float64})

Supported types are:

  • boolean - :bool
  • float - :float64, :float32
  • integer - :int64, :int32, :int16, :int8
  • unsigned integer - :uint64, :uint32, :uint16, :uint8
  • object - :object

Get column types

ruby
df.types

For a specific column

ruby
df[:a].type

Change the type of a column

ruby
df[:a].to!(:int32)

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

  • Report bugs
  • Fix bugs and submit pull requests
  • Write, clarify, or fix documentation
  • Suggest or add new features

To get started with development:

bash
git clone https://github.com/ankane/rover.git
cd rover
bundle install
bundle exec rake test

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言