Code Monkey home page Code Monkey logo

tablesaw's Introduction

Tablesaw

Tablesaw is a high-performance, in-memory data table, combined with tools for data manipulation, and a column-oriented storage format. In Java.

With Tablesaw, you can import, sort, transform, filter, and summarize tables of up to one billion rows on a laptop. Tablesaw uses tricks from high-frequency trading apps (e.g. primitive collections) and data warehouses (e.g. compressed, column-oriented storage and data structures), to maximize what you can do in a single VM.

The goal is to make all but the biggest data wrangling jobs approachable without the complexity of distributed computing (HDFS, Hadoop, etc.). Analysis is more productive with less engineering overhead and shorter iteration cycles. A fluent API lets developers express operations in a concise and readable fashion.

Tablesaw provides general-purpose analytic support, with rich functionality for working with time-series, including specialized column types for dates, times, timestamps and intervals.

I'm aiming for usability at least as good as R dataframes or Pandas. And with Java 9, you'll be able to work interactively in the REPL.

For more information and examples see: https://javadatascience.wordpress.com

An introduction in 9 lines of code

Here's an example. In 9 lines of trivial code, we will:

  • Read a CSV file
  • Print the first few rows for a peak at the data
  • Sort the table by column name
  • Run descriptive statistics (mean, min, max, etc.) on a column
  • Remove a column
  • Create a new column as the sum of the values in two existing columns
  • Filter some rows
  • Save the new version as a file

Read a CSV file

Here we read a csv file of bus stop data. First, we say what column types are present.

    ColumnType[] types = {INTEGER, TEXT, TEXT, FLOAT, FLOAT};
    Table table = CsvReader.read("data/bus_stop_test.csv", types);

Viewing data

The head(n) method returns the first n rows.

    table.head(3);
    

producing:

data/bus_stop_test.csv
stop_id stop_name                stop_desc                                                stop_lat  stop_lon   
66      4925 CRAIGWOOD/FM 969    Southeast corner of CRAIGWOOD and FM 969 - Nearside      30.28417  -97.65985  
252     200 TRINITY/2ND          Northeast corner of TRINITY and 2ND - Mid-Block          30.263842 -97.740425 
462     851 RUTLAND/PARK VILLAGE Southeast corner of RUTLAND and PARK VILLAGE - Mid-Block 30.36547  -97.69752  

Sorting by column

Now that we've some some data, lets sort the table in reverse order by the id column

    table.sortDescendingOn("stop_id");

Removing a column

    table.removeColumn("stop_desc");

Descriptive statistics

    table.column("stop_lon").describe();

This outputs:

Descriptive Stats 
n: 2729
missing: 0
min: -97.9911
max: -97.37039
range: 0.62070465
mean: -97.73799133300781
std.dev: 0.049913406
variance: 0.0024913481902331114

Create new columns from the data in existing columns

Now let's add a column derived from the existing data. We can map arbitrary lambda expressions onto the data table, but many, many common operations (add, subtract, multiply, max, etc.) are built in. For example, for a column-wise addition:

    Column total = add(table.get("stop_lat", "stop_lon"));

(Yeah, I know that's a stupid example. Imagine it was two columns you'd actually want to add.)

Filtering Rows

To filter records you can also be arbitrary lambda expressions, but it's often easier to use the built-in filter classes as shown below:

Table f = table.selectIf(column("stop_id").isBetween(524, 624)));

Write the new CSV file to disk

CsvWriter.write("filtered_bus_stops.csv", f);

This is just the beginning of what Tablesaw can do. Other features include:

  • Powerful Group-by functionality (aka: Split, Aggregate, Combine)
  • Map arbitrary lambda expressions over tables

More advanced operations are described on the project web site: https://javadatascience.wordpress.com

A work-in-progress

Tablesaw is in an experimental state, with a production release planned for late 2016. A great deal of additional functionality is planned, including window operations (like rolling averages), outlier detection, and integrated machine-learning.

tablesaw's People

Contributors

lwhite1 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.