GithubHelp home page GithubHelp logo

victoriaquasar / datatable Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mikestall/datatable

0.0 0.0 0.0 568 KB

Class library for working with tabular data, especially CSV files

License: Apache License 2.0

C# 99.95% Batchfile 0.05%

datatable's Introduction

##C# project for reading and writing CSVs

Fast streaming CSV parser. Libraries for easy reading, writing, and manipulation of CSV files. Is able to handle:

  • CSV file format corner cases including escaped values, newlines, and error recovery
  • Linq and binding CSV rows directly to .NET objects
  • Creating tables from IEnumerable<T>
  • In-memory mutable tables
  • Streaming through large tables.
  • Dictionaries
  • 2D-Dictionary support and converting to CSVs. Great for sparse-arrays.

It's an easier data table than System.Data.DataTable.

The following nuget packages are available:

A few quick examples:

Download as CsvTools from Nuget to include in your C# project:

using DataAccess;
// See methods on DataTable.New for loading a DataTable.
var dt = DataTable.New.ReadLazy(filename); // Fast streaming load a CSV from disk. 

Get a mutable datatable:

MutableDataTable dt = DataTable.New.ReadCsv(filename); // load entire CSV into memory for mutation 
int totalRows = dt.NumRows;

// Includes mutation methods like:
//  CreateColumn, ReorderColumn, KeepColumns, RenameColumn, 
//  GetRow(int rowIndex), KeepRows(Func<T, bool> predicate)

dt.SaveCsv(filename); // write back out

Linq against the rows:

var y = from row in dt.Rows where row["N"] == "3" select row["NSquared"];

Linq with strongly-typed parsing, using RowAs<T>() method:

class Entry
{
  public int N { get; set; }
  public int NSquared { get; set; }
}
int y = (from row in dt.RowsAs<Entry>() where row.N == 3 select row.NSquared).First();

Create a table around an IEnumerable and then save back as a CSV:

var x = from i in Enumerable.Range(1, 5) select new { N = i, NSquared = i * i };
DataTable dt = DataTable.New.FromEnumerable(x);
dt.SaveToStream(Console.Out); // write back out as a CSV

Also includes support for reading an excel file (.xlsx):

var dt = DataTable.New.ReadExcel(@"c:\temp\foo.xlsx");
var names = from row in dt.Rows where int.Parse(row["age"]) > 10 select row["Name"];

See here for more about reading excel.

datatable's People

Contributors

aaronhoffman avatar bradwilson avatar jordan-m avatar mikestall avatar mskiy avatar pietervp avatar stephengodbold avatar ti24horas avatar tpwalke2 avatar vagyokc4 avatar yellis 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.