# tabdat

> Process tabular data efficiently and easily.

Latest version **0.0.3** (published 2019-06-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install tabdat
pnpm add tabdat
yarn add tabdat
bun add tabdat
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2019-06-27 |
| First published | 2019-05-31 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 8.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Matt Helm |
| Maintainers | mthelm85 |
| Keywords | tabular, data, data, processing, data, wrangling |

## Links

- npm: https://www.npmjs.com/package/tabdat
- Homepage: https://github.com/mthelm85/tabdat
- npm.io page: https://npm.io/package/tabdat

## Dependencies (3)

- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [papaparse](https://npm.io/package/papaparse.md) ^5.0.0
- [console.table](https://npm.io/package/console.table.md) ^0.10.0

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 0.0.3 (latest) — 2019-06-27
- 0.0.2 — 2019-06-27
- 0.0.1 — 2019-06-27
- 1.0.1 — 2019-06-27
- 1.0.0 — 2019-05-31

## README

### 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

```javascript
npm i tabdat
```

### Usage

The standard workflow looks like this:

```javascript
const TabDat = require('tabdat')

TabDat.convert('/path/to/file.csv').then(data => {
  td = new TabDat.TabDat(data)
  td.sortBy(row => row.mpg)
    .filter(row => countryOfOrigin === 'USA')
    .printTable()
})
```
Note that all methods are chainable.

### Available Methods

#### Convert

```javascript
convert(filepath)
```
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
```javascript
addCol(name, userFunction)
```

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:

```javascript
addCol('myNewCol', row => row.mpg * 2)
```

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
```javascript
addRow(row)
```
Adds a new row to the data. ```row``` is an object.

For example:

```javascript
addRow({
  countryOfOrigin: 'USA',
  mpg: 28,
  numCylinders: 6
})
```
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
```javascript
deleteCol(colNames)
```
Deletes the column(s) that are specified in the array ```colNames```.

For example:
```javascript
deleteCol(['mpg', 'numCylinders'])
```
__________________________________________________________________________________________________
#### Filter the data
```javascript
filter(userFunction)
```
Filters the data based on the provided function.

For example:
```javascript
filter(row => row.mpg > 30)
```
__________________________________________________________________________________________________
#### Print the column names to the console
```javascript
printColNames()
```
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
```javascript
printTable()
```
Prints the data to the console in a tabular format.
___________________________________________________________________________________________________
#### Rename a column
```javascript
renameCol(oldColName, newColName)
```
Renames the column ```oldColName``` to the name provided in ```newColName```. Both arguments are strings.

For example:
```javascript
renameCol('countryOfOrigin', 'country')
```
This will change the name of the column ```countryOfOrigin``` to ```country```.
___________________________________________________________________________________________________
#### Save the data to a CSV file
```javascript
save(filepath)
```
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:
```javascript
save('path/to/save/to.csv')
```
__________________________________________________________________________________________________
#### Get the number of rows and columns (printed to the console)
```javascript
size()
```
Prints to the console the current number of rows/columns the data consists of.
__________________________________________________________________________________________________
#### Sort the data
```javascript
sortBy(criteria)
```
Sorts the data by the given criteria which can either be a function or an array.

For example:
```javascript
sortBy(row => row.mpg)
```
This will sort the data in ascending order by the values in the ```mpg``` column.

```javascript
sortBy(['countryOfOrigin', 'mpg'])
```
This will sort the data first by ```countryOfOrigin``` and then by ```mpg```.

---
_Source: https://npm.io/package/tabdat · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
