Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
D

daru

> 编程语言
Open source

Data Analysis in RUby

1.1K stars0 likes1 views
WebsiteGitHub

About

Data Analysis in RUby

daru - Data Analysis in RUby

Introduction

daru (Data Analysis in RUby) is a library for storage, analysis, manipulation and visualization of data in Ruby.

daru makes it easy and intuitive to process data predominantly through 2 data structures: Daru::DataFrame and Daru::Vector. Written in pure Ruby works with all ruby implementations. Tested with MRI 2.5.1 and 2.7.1.

daru plugin gems

  • daru-view

daru-view is for easy and interactive plotting in web application & IRuby notebook. It can work in any Ruby web application frameworks like Rails, Sinatra, Nanoc and hopefully in others too.

Articles/Blogs, that summarize powerful features of daru-view:

  • GSoC 2017 daru-view
  • GSoC 2018 Progress Report
  • HighCharts Official blog post regarding daru-view
  • daru-io

This gem extends support for many Import and Export methods of Daru::DataFrame. This gem is intended to help Rubyists who are into Data Analysis or Web Development, by serving as a general purpose conversion library that takes input in one format (say, JSON) and converts it another format (say, Avro) while also making it incredibly easy to getting started on analyzing data with daru. One can read more in SciRuby/blog/daru-io.

Features

  • Data structures:
    • Vector - A basic 1-D vector.
    • DataFrame - A 2-D spreadsheet-like structure for manipulating and storing data sets. This is daru's primary data structure.
  • Compatible with IRuby notebook, statsample, statsample-glm and statsample-timeseries.
  • Support for time series.
  • Singly and hierarchically indexed data structures.
  • Flexible and intuitive API for manipulation and analysis of data.
  • Easy plotting, statistics and arithmetic.
  • Plentiful iterators.
  • Optional speed and space optimization on MRI with NMatrix and GSL.
  • Easy splitting, aggregation and grouping of data.
  • Quickly reducing data with pivot tables for quick data summary.
  • Import and export data from and to Excel, CSV, SQL Databases, ActiveRecord and plain text files.

Installation

bash
$ gem install daru

Notebooks

Notebooks on most use cases

  • Overview of most daru functions
  • Basic Creation of Vectors and DataFrame
  • Detailed Usage of Daru::Vector
  • Detailed Usage of Daru::DataFrame
  • Searching and combining data in daru
  • Grouping, Splitting and Pivoting Data
  • Usage of Categorical Data

Visualization

  • Visualizing Data With Daru::DataFrame
  • Plotting using Nyaplot
  • Plotting using GnuplotRB
  • Vector plotting with Gruff
  • DataFrame plotting with Gruff

Notebooks on Time series

  • Basic Time Series
  • Time Series Analysis and Plotting

Notebooks on Indexing

  • Indexing in Vector
  • Indexing in DataFrame

Case Studies

  • Logistic Regression Analysis with daru and statsample-glm
  • Finding and Plotting most heard artists from a Last.fm dataset
  • Analyzing baby names with daru
  • Example usage of Categorical Data
  • Example usage of Categorical Index

Blog Posts

  • Data Analysis in RUby: Basic data manipulation and plotting
  • Data Analysis in RUby: Splitting, sorting, aggregating data and data types
  • Finding and Combining data in daru
  • Introduction to analyzing datasets with daru library

Time series

  • Analysis of Time Series in daru
  • Date Offsets in Daru

Categorical Data

  • Categorical Index
  • Categorical Data
  • Visualization with Categorical Data

Basic Usage

daru exposes two major data structures: DataFrame and Vector. The Vector is a basic 1-D structure corresponding to a labelled Array, while the DataFrame - daru's primary data structure - is 2-D spreadsheet-like structure for manipulating and storing data sets.

Basic DataFrame intitialization.

ruby
data_frame = Daru::DataFrame.new(
  {
    'Beer' => ['Kingfisher', 'Snow', 'Bud Light', 'Tiger Beer', 'Budweiser'],
    'Gallons sold' => [500, 400, 450, 200, 250]
  },
  index: ['India', 'China', 'USA', 'Malaysia', 'Canada']
)
data_frame

Load data from CSV files.

ruby
df = Daru::DataFrame.from_csv('TradeoffData.csv')

Basic Data Manipulation

Selecting rows.

ruby
data_frame.row['USA']

Selecting columns.

ruby
data_frame['Beer']

A range of rows.

ruby
data_frame.row['India'..'USA']

The first 2 rows.

ruby
data_frame.first(2)

The last 2 rows.

ruby
data_frame.last(2)

Adding a new column.

ruby
data_frame['Gallons produced'] = [550, 500, 600, 210, 240]

Creating a new column based on data in other columns.

ruby
data_frame['Demand supply gap'] = data_frame['Gallons produced'] - data_frame['Gallons sold']

Condition based selection

Selecting countries based on the number of gallons sold in each. We use a syntax similar to that defined by Arel, i.e. by using the where clause.

ruby
data_frame.where(data_frame['Gallons sold'].lt(300))

You can pass a combination of boolean operations into the #where method and it should work fine:

ruby
data_frame.where(
  data_frame['Beer']
  .in(['Snow', 'Kingfisher','Tiger Beer'])
  .and(
    data_frame['Gallons produced'].gt(520).or(data_frame['Gallons produced'].lt(250))
  )
)

Plotting

Daru supports plotting of interactive graphs with nyaplot. You can easily create a plot with the #plot method. Here we plot the gallons sold on the Y axis and name of the brand on the X axis in a bar graph.

ruby
data_frame.plot type: :bar, x: 'Beer', y: 'Gallons sold' do |plot, diagram|
  plot.x_label "Beer"
  plot.y_label "Gallons Sold"
  plot.yrange [0,600]
  plot.width 500
  plot.height 400
end

In addition to nyaplot, daru also supports plotting out of the box with gnuplotrb.

Documentation

Docs can be found here.

Contributing

Pick a feature from the Roadmap or the issue tracker or think of your own and send me a Pull Request!

For details see CONTRIBUTING.

Acknowledgements

  • Google and the Ruby Science Foundation for the Google Summer of Code 2016 grant for speed enhancements and implementation of support for categorical data. Special thanks to @lokeshh, @zverok and @agisga for their efforts.
  • Google and the Ruby Science Foundation for the Google Summer of Code 2015 grant for further developing daru and integrating it with other ruby gems.
  • Thank you last.fm for making user data accessible to the public.

Copyright (c) 2015, Sameer Deshmukh All rights reserved

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

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