About
TabDat is a package for working with tabular data in CSV format. It leverages Papa Parse for the CSV to JSON conversion, and then mostly utilizes Lodash for the manipulation of the data. It is intended for users who want to easily work with tabular data in Node.js and particularly for users who may be used to working with data frames in R/Python/etc.
Contributing
This is a side project (read: low priority) of mine so any contributions are welcome - just submit a pull request on GitHub. I really would like to see a robust Node.js package that allows for working with tabular data in a way that is similar to R/Python so I am hoping to get additional contributors and to be able to really flesh this package out in a thorough manner.
Installation
npm i tabdat
Usage
The standard workflow looks like this:
const TabDat = TabDat
Note that all methods are chainable.
Available Methods
Convert
Converts a CSV file to JSON for further processing. filepath
is a string pointing to the correct location. Returns a promise with the converted data.
Add a new column
Adds a new column to the data and populates the column via the provided userFunction
. name
is a string representing the name of the new column and userFunction
is a function.
For example:
This will create a new row called myNewCol
and the values in this column will be the product of the value in the mpg
column and 2.
Add a new row
Adds a new row to the data. row
is an object.
For example:
Note: The keys of the object must match those that are already in the data (i.e. you can't add a new column this way, use addCol
for that).
Delete a column
Deletes the column(s) that are specified in the array colNames
.
For example:
Filter the data
Filters the data based on the provided function.
For example:
Print the column names to the console
Prints to the console an array containing all of the current column names (object keys) in the data.
Print the data as a table to the console
Prints the data to the console in a tabular format.
Rename a column
Renames the column oldColName
to the name provided in newColName
. Both arguments are strings.
For example:
This will change the name of the column countryOfOrigin
to country
.
Save the data to a CSV file
Saves the data in its current state to a CSV file in the location provided in the filepath
argument (which is a string).
For example:
Get the number of rows and columns (printed to the console)
Prints to the console the current number of rows/columns the data consists of.
Sort the data
Sorts the data by the given criteria which can either be a function or an array.
For example:
This will sort the data in ascending order by the values in the mpg
column.
This will sort the data first by countryOfOrigin
and then by mpg
.