Introduction
pandas.js is an open source (experimental) library mimicking the Python
pandas library. It relies on
Immutable.js as the
NumPy logical equivalent. The main data objects in pandas.js are, like
in Python pandas, the Series
and the DataFrame
.
Installation and use
Installation
npm install pandas-js
npm install git+https://github.com/StratoDem/pandas.js
Import
import { Series, DataFrame } from 'pandas-js';
var Series = require('pandas-js').Series;
var DataFrame = require('pandas-js').DataFrame;
Create a new series
const ds_1 = new Series([1, 2, 3, 4], {name: 'My Data 1'});
console.log('This is a Series');
console.log(ds_1.toString());
console.log(`Sum: ${ds_1.sum()}`);
console.log(`Standard deviation: ${ds_1.std()}`);
outputs:
> This is a Series
0 1
1 2
2 3
Name: My Data 1, dtype: dtype(int)
Sum: 10
Standard deviation: 1
const ds_2 = new Series([2, 3, 4, 5], {name: 'My Data 2'});
console.log('Summing two Series:');
console.log(ds_1.plus(ds_2).toString());
A Series
object is a one-dimensional named Immutable.List of values.
Series parameters
Parameter | Description | Default |
---|---|---|
data | Iterable of values to store in the Series | |
kwargs | Extra arguments for indexing and naming the Series | {name: ""} |
kwargs.name | Name of the series | "" |
kwargs.index | Indexing to use for series | range(0, data.length) |
outputs:
> Summing two Series:
0 3
1 5
2 7
3 9
Name: , dtype: dtype(int)
Series
New Series
const ds = new Series([1, 2, 3, 4], {name: 'My test name', index: [2, 3, 4, 5]})
ds.toString()
// Returns:
// 2 1
// 3 2
// 4 3
// 5 4
// Name: My test name, dtype: dtype(int)
One dimensional array with axis labels. An Immutable.List
serves as the numpy.ndarray for
values.
Operations between Series
(+, -, /, , *) align values based on their associated index
values
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
data | Data to be stored in Series | None | Array, List |
kwargs | Extra optional arguments for a Series | None | Object |
kwargs.name | The _name to assign to the Series | '' | string |
kwargs.index | None | Array, List |
Series.abs
const ds = new Series([-1, 2, -4, 5, -1, -2]);
// Returns Series([1, 2, 4, 5, 1, 2]);
ds.abs();
Return Series with absolute value of all values
pandas equivalent: Series.abs
Series.add
const ds = new Series([1, 2, 3], {name: 'New Series'})
ds.add(5) // Series([6, 7, 8], {name: 'New Series'})
ds.add(new Series([2, 3, 4])) // Series([3, 5, 7], {name: 'New Series'})
ds.add([2, 3, 4]) // Series([3, 5, 7], {name: 'New Series'})
ds.add(Immutable.List([2, 3, 4])) // Series([3, 5, 7], {name: 'New Series'})
Add another Iterable, Series
, or number to the Series
pandas equivalent: Series.add
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
other | Value to add to the Series |
None | Iterable, Series, number |
Returns Series
Series.append
const ds1 = new Series([1, 2, 3], {index: [1, 2, 3]});
const ds2 = new Series([2, 3, 4], {index: [3, 4, 5]});
// Returns Series([1, 2, 3, 2, 3, 4], {index: [1, 2, 3, 3, 4, 5]});
ds1.append(ds2);
// Returns Series([1, 2, 3, 2, 3, 4], {index: [0, 1, 2, 3, 4, 5]});
ds1.append(ds2, true);
Append another Series to this and return a new Series
pandas equivalent: Series.append
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
other | None | Series | |
ignore_index | False | boolean |
Returns Series
Series.astype
const ds = new Series([1.5, 2, 3], {name: 'Series name'});
// dtype('float')
ds.dtype;
// Series([1, 2, 3])
ds.astype(new DType('int'))
Convert the series to the desired type
pandas equivalent: Series.astype
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
nextType | None | DType |
Series.copy
const ds = new Series([1, 2, 3], {name: 'Test 1'});
const ds2 = ds.copy();
ds2.index = [1, 2, 3];
ds.index // [0, 1, 2];
ds2.index // [1, 2, 3];
Return a new deep copy of the Series
pandas equivalent: Series.copy
Series.corr
const ds1 = new Series([1, 2, 3, 4, 5]);
const ds2 = new Series([2, 4, 6, 8, 10]);
// Returns 1
ds1.corr(ds2);
// Also returns 1
ds2.corr(ds1);
Calculate the correlation between this Series
and another Series
or iterable
pandas equivalent: Series.corr
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
ds | Series with which to calculate correlation | None | Series |
Returns number
Series.cov
const ds1 = new Series([1, 2, 3, 4, 5]);
const ds2 = new Series([2, 4, 6, 8, 10]);
// Returns 5
ds1.cov(ds2);
// Also returns 5
ds2.cov(ds1);
Calculate the covariance between this Series
and another Series
or iterable
pandas equivalent: Series.cov
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
ds | Series with which to calculate covariance | None | Series |
Returns number
Series.cummax
const ds = new Series([3, 2, 4], {index: [2, 3, 4]});
// Returns Series([3, 3, 4], {index: [2, 3, 4]});
ds.cummax();
Return cumulative max over requested axis
pandas equivalent: Series.cummax
Series.cummin
const ds = new Series([1, 2, 3], {index: [2, 3, 4]});
// Returns Series([1, 1, 1], {index: [2, 3, 4]});
ds.cummin();
Return cumulative min over requested axis
pandas equivalent: Series.cummin
Series.cummul
const ds = new Series([1, 2, 3], {index: [2, 3, 4]});
// Returns Series([1, 2, 6], {index: [2, 3, 4]});
ds.cummul();
Return cumulative mul over requested axis
pandas equivalent: Series.cummul
Series.cumsum
const ds = new Series([1, 2, 3], {index: [2, 3, 4]});
// Returns Series([1, 3, 6], {index: [2, 3, 4]});
ds.cumsum();
Return cumulative sum over requested axis
pandas equivalent: Series.cumsum
Series.diff
const ds = new Series([1, 2, 6, 5])
// Returns Series([null, 1, 4, -1])
ds.diff();
// Returns Series([null, null, 5, 3])
ds.diff(2);
Return the difference over a given number of periods
pandas equivalent: Series.diff
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
periods | Number of periods to use for difference calculation | 1 | number |
Returns Series
Series.div
const ds = new Series([1, 2, 3], {name: 'New Series'})
ds.div(5) // Series([0.2, 0.4, 0.6], {name: 'New Series'})
ds.div(new Series([4, 2, 1])) // Series([0.25, 1, 3], {name: 'New Series'})
ds.div([4, 2, 1]) // Series([0.25, 1, 3], {name: 'New Series'})
ds.div(Immutable.List([4, 2, 1])) // Series([0.25, 1, 3], {name: 'New Series'})
Divide by another Iterable, Series
, or number from the Series
pandas equivalent: Series.div
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
other | Value by which to divide the Series |
None | Iterable, Series, number |
Returns Series
Series.divide
const ds = new Series([1, 2, 3], {name: 'New Series'})
ds.divide(5) // Series([0.2, 0.4, 0.6], {name: 'New Series'})
ds.divide(new Series([4, 2, 1])) // Series([0.25, 1, 3], {name: 'New Series'})
ds.divide([4, 2, 1]) // Series([0.25, 1, 3], {name: 'New Series'})
ds.divide(Immutable.List([4, 2, 1])) // Series([0.25, 1, 3], {name: 'New Series'})
Divide by another Iterable, Series
, or number from the Series
pandas equivalent: Series.divide
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
other | Value by which to divide the Series |
None | Iterable, Series, number |
Returns Series
Series.dtype
const ds = new Series([1.5, 2, 3], {name: 'Series name'});
ds.dtype; // dtype('float');
Return the dtype of the underlying data
pandas equivalent Series.dtype
Series.eq
const ds = new Series([1, 2, 3], {name: 'Test name'})
// Returns Series([true, false, false])
ds.eq(1);
// Returns Series([false, true, true])
ds.eq(new Series([0, 2, 3]));
// Returns Series([false, true, true])
ds.eq(Immutable.List([0, 2, 3]));
// Returns Series([false, true, true])
ds.eq([0, 2, 3]);
Equal to of Series
and other, element wise
pandas equivalent: Series == val
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
other | Other Series or scalar value to check for equality |
None | Series, Array, List, number, string |
Returns Series
Series.filter
const ds = new Series([1, 2, 3]);
// Returns Series([2, 3]);
ds.filter(ds.gte(2));
Filter the Series by an Iterable (Series, Array, or List) of booleans and return the subset
pandas equivalent: series[series condition]
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
iterBool | Iterable of booleans | None | Series, Array, List |
Returns Series
Series.gt
const ds = new Series([1, 2, 3], {name: 'Test name'})
// Returns Series([false, true, true])
ds.gt(1);
// Returns Series([true, false, false])
ds.gt(new Series([0, 2, 3]));
// Returns Series([true, false, false])
ds.gt(Immutable.List([0, 2, 3]));
// Returns Series([true, false, false])
ds.gt([0, 2, 3]);
Greater than of Series
and other, element wise
pandas equivalent: Series > val
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
other | Other Series or scalar value to check for greater than |
None | Series, Array, List, number, string |
Returns Series
Series.gte
const ds = new Series([1, 2, 3], {name: 'Test name'})
// Returns Series([true, true, true])
ds.gte(1);
// Returns Series([true, true, false])
ds.gte(new Series([0, 2, 4]));
// Returns Series([true, true, false])
ds.gte(Immutable.List([0, 2, 4]));
// Returns Series([true, true, false])
ds.gte([0, 2, 4]);
Greater than or equal to of Series
and other, element wise
pandas equivalent: Series >= val
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
other | Other Series or scalar value to check for greater than or equal to |
None | Series, Array, List, number, string |
Returns Series
Series.head
const ds = new Series([1, 2, 3, 4, 5, 6, 7, 8]);
// Returns Series([1, 2, 3, 4, 5])
ds.head();
// Returns Series([1, 2, 3])
ds.head(3);
Return first n rows
pandas equivalent: Series.head
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
n | 5 | number |
Returns Series
Series.iloc
const ds = new Series([1, 2, 3, 4], {name: 'New Series'})
ds.iloc(1) // 2
ds.iloc(1, 3) // Series([2, 3], {name: 'New Series', index: [1, 2]})
Return the Series between [startVal, endVal), or at startVal if endVal is undefined
pandas equivalent: Series.iloc
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
startVal | None | int | |
endVal | None | int |
Returns Series, number, string
Series.index
const ds = new Series([1.5, 2, 3], {name: 'Series name'});
// Returns List [0, 1, 2]
ds.index;
Return the index of the Series
, an Immutable.List
Series.index
const ds = new Series([1.5, 2, 3], {name: 'Series name'});
ds.index = [1, 2, 3];
// Returns List [1, 2, 3]
ds.index;
Set the index of the Series
, an Immutable.List
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
index | The next values for the index of the Series |
None | List, Array |
Series.length
const ds = new Series([1.5, 2, 3], {name: 'Series name'});
// Returns 3
ds.length;
Return the length of the Series
pandas equivalent: len(series);
Series.lt
const ds = new Series([1, 2, 3], {name: 'Test name'})
// Returns Series([false, false, false])
ds.lt(1);
// Returns Series([false, false, true])
ds.lt(new Series([0, 2, 4]));
// Returns Series([false, false, true])
ds.lt(Immutable.List([0, 2, 5]));
// Returns Series([false, false, true])
ds.lt([0, 2, 5]);
Less than of Series
and other, element wise
pandas equivalent: Series < val
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
other | Other Series or scalar value to check for less than |
None | Series, Array, List, number, string |
Returns Series
Series.lte
const ds = new Series([1, 2, 3], {name: 'Test name'})
// Returns Series([false, false, false])
ds.lte(1);
// Returns Series([false, false, true])
ds.lte(new Series([0, 2, 4]));
// Returns Series([false, false, true])
ds.lte(Immutable.List([0, 2, 5]));
// Returns Series([false, false, true])
ds.lte([0, 2, 5]);
Less than or equal to of Series
and other, element wise
pandas equivalent: Series <= val
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
other | Other Series or scalar value to check for less than or equal to |
None | Series, Array, List, number, string |
Returns Series
Series.map
const ds = new Series([1, 2, 3, 4], {name: 'New Series'})
// Returns Series([1, 4, 9, 16], {name: 'New Series', index: [1, 2]})
ds.map((val, idx) => val ** 2;
Return a new Series
created by a map along a Series
pandas equivalent: Series.map
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
func | Function to apply along the values | None | function |
Returns Series
Series.mean
const ds = new Series([1, 2, 3, 4], {name: 'New Series'})
// Returns 2.5
ds.mean();
Return the mean of the values in the Series
pandas equivalent: Series.mean
Series.median
const ds = new Series([2, 3, 1, 4, 5], {name: 'New Series'})
// Returns 3
ds.median();
Return the median of the values in the Series
pandas equivalent: Series.median
Series.mul
const ds = new Series([1, 2, 3], {name: 'New Series'})
ds.mul(5) // Series([5, 10, 15], {name: 'New Series'})
ds.mul(new Series([2, 3, 4])) // Series([2, 6, 12], {name: 'New Series'})
ds.mul([2, 3, 4]) // Series([2, 6, 12], {name: 'New Series'})
ds.mul(Immutable.List([2, 3, 4])) // Series([2, 6, 12], {name: 'New Series'})
Multiply by another Iterable, Series
, or number from the Series
pandas equivalent: Series.mul
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
other | Value to multiply by the Series |
None | Iterable, Series, number |
Returns Series
Series.multiply
const ds = new Series([1, 2, 3], {name: 'New Series'})
ds.multiply(5) // Series([5, 10, 15], {name: 'New Series'})
ds.multiply(new Series([2, 3, 4])) // Series([2, 6, 12], {name: 'New Series'})
ds.multiply([2, 3, 4]) // Series([2, 6, 12], {name: 'New Series'})
ds.multiply(Immutable.List([2, 3, 4])) // Series([2, 6, 12], {name: 'New Series'})
Multiply by another Iterable, Series
, or number from the Series
pandas equivalent: Series.multiply
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
other | Value to multiply by the Series |
None | Iterable, Series, number |
Returns Series
Series.name
Return the name of the Series
Series.notnull
const ds = new Series([1, 2, null, null, 4]);
// Returns Series([true, true, false, false, true])
ds.notnull();
Returns a boolean same-sized Series indicating if the values are not null
pandas equivalent: Series.notnull
Series.pct_change
const ds = new Series([1, 2, 3, 4, 5], {name: 'New Series'})
ds.pct_change(1) // Series([null, 1, 0.5, 0.333, 0.25], {name: 'New Series'})
ds.pct_change(2) // Series([null, null, 2, 1, 0.66666], {name: 'New Series'})
Return the percentage change over a given number of periods
pandas equivalent: Series.pct_change
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
periods | Number of periods to use for percentage change calculation | 1 | number |
Returns Series
Series.rename
const ds = new Series([1, 2, 3], {name: 'Test name'});
ds.rename('New test name');
// returns 'New test name'
ds.name;
Rename the Series
and return a new Series
pandas equivalent: Series.rename
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
name | None | string |
Series.round
const ds = new Series([1.25, 1.47, 1.321])
// Returns Series([1.3, 1.5, 1.3])
ds.round(1);
Return a Series
with all values rounded to the nearest precision specified by decimals
pandas equivalent: Series.round
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
decimals | Number of decimals to round to | 0 | number |
Series.shift
const ds = new Series([1, 2, 3, 4]);
// Returns Series([null, 1, 2, 3]);
ds.shift(1);
// Returns Series([null, null, 1, 2]);
ds.shift(2);
// Returns Series([3, 4, null, null]);
ds.shift(-2);
Shift index by desired number of periods
pandas equivalent:s Series.shift
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
periods | Number of periods to move, can be positive or negative | 1 | number |
Returns Series
Series.sort_values
const ds = new Series([2, 1, 0, 3], {name: 'New Series', index: [0, 1, 2, 3]})
ds.sort_values(true) // Series([0, 1, 2, 3], {name: 'New Series', index: [2, 1, 0, 3]})
ds.sort_values(false) // Series([3, 2, 1, 0], {name: 'New Series', index: [3, 0, 1, 2]})
Return a sorted Series
in either ascending or descending order
pandas equivalent: Series.sort_values
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
ascending | Sort in ascending (true) or descending (false) order | True | boolean |
Returns Series
Series.std
const ds = new Series([1, 2, 3], {name: 'New Series'})
// Returns 1
ds.std();
Return the standard deviation of the values in the Series
pandas equivalent: Series.std
Series.sub
const ds = new Series([1, 2, 3], {name: 'New Series'})
ds.sub(5) // Series([-4, -3, -2], {name: 'New Series'})
ds.sub(new Series([2, 3, 4])) // Series([-1, -1, -1], {name: 'New Series'})
ds.sub([2, 3, 4]) // Series([-1, -1, -1], {name: 'New Series'})
ds.sub(Immutable.List([2, 3, 4])) // Series([-1, -1, -1], {name: 'New Series'})
Subtract another Iterable, Series
, or number from the Series
pandas equivalent: Series.sub
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
other | Value to subtract from the Series |
None | Iterable, Series, number |
Returns Series
Series.sum
const ds = new Series([1, 2, 3, 4], {name: 'New Series'})
// Returns 10
ds.sum();
Return the sum of the values in the Series
pandas equivalent: Series.sum
Series.tail
const ds = new Series([1, 2, 3, 4, 5, 6, 7, 8]);
// Returns Series([4, 5, 6, 7, 8])
ds.tail();
// Returns Series([6, 7, 8])
ds.tail(3);
Return last n rows
pandas equivalent: Series.tail
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
n | 5 | number |
Returns Series
Series.toString
const ds = new Series([1, 2, 3, 4], {name: 'My test name', index: [2, 3, 4, 5]})
ds.toString()
// Returns:
// 2 1
// 3 2
// 4 3
// 5 4
// Name: My test name, dtype: dtype(int)
Return the Series
as a string
Series.to_json
const ds = new Series([1, 2, 3], {name: 'x'});
// Returns {0: 1, 1: 2, 2: 3}
ds.to_json();
// Returns [1, 2, 3]
ds.to_json({orient: 'records'});
// Returns {index: [0, 1, 2], name: 'x', values: [1, 2, 3]}
ds.to_json({orient: 'split'});
Convert the Series to a json object
pandas equivalent: Series.to_json
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
kwargs | None | None | |
kwargs.orient | orientation of JSON | columns | string |
Returns *
Series.unique
const ds = new Series(['foo', 'bar', 'bar', 'foo', 'foo', 'test', 'bar', 'hi']);
// Returns ['foo', 'bar', 'test', 'hi']
ds.unique();
Returns Immutable.List
of unique values in the Series
. Preserves order of the original
pandas equivalent: Series.unique
Series.values
const ds = new Series([1.5, 2, 3], {name: 'Series name'});
// Returns List [1.5, 2, 3]
ds.values;
Return the values of the Series
as an Immutable.List
pandas equivalent: Series.values;
Series.variance
const ds = new Series([1, 2, 3], {name: 'New Series'})
// Returns 1
ds.variance();
Return the variance of the values in the Series
pandas equivalent: Series.var
Series.where
const ds = new Series([1, 2, 3], {name: 'Test name'})
// Returns Series([true, false, false])
ds.where(1, (v1, v2) => v1 === 1);
// Returns Series([false, true, true])
ds.where(new Series([0, 2, 3]), (v1, v2) => v1 === v2);
Flexible comparison of an iterable or value to the Series
. Returns a Series
of booleans of
equivalent length
pandas equivalent: Series.where
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
other | Iterable or value compared to Series | None | Series, Array, List, string, number |
op | Function which takes (a, b) values and returns a boolean | None | function |
Returns Series
DataFrame
New DataFrame
const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}])
// Returns:
// x | y
// 0 1 | 2
// 1 2 | 3
// 2 3 | 4
df.toString();
Two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns). Arithmetic operations align on both row and column labels. Can be thought of as a Immutable.Map-like container for Series objects. The primary pandas data structure
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
data | Data to be stored in DataFrame | None | Array, Object |
kwargs | Extra optional arguments for a DataFrame | None | Object |
kwargs.index | None | Array, Object |
DataFrame.append
const df1 = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}], {index: [1, 2]});
const df2 = new DataFrame([{x: 2, y: 2}, {x: 3, y: 3}], {index: [2, 3]});
// Returns DataFrame(
[{x: 1, y: 2}, {x: 2, y: 3}, {x: 2, y: 2}, {x: 3, y: 3}],
{index: [1, 2, 2, 3]});
df1.append(df2);
// Returns DataFrame(
[{x: 1, y: 2}, {x: 2, y: 3}, {x: 2, y: 2}, {x: 3, y: 3}],
{index: [0, 1, 2, 3]});
df1.append(df2, true);
Append another DataFrame to this and return a new DataFrame
pandas equivalent: DataFrame.append
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
other | None | DataFrame | |
ignore_index | False | boolean |
Returns DataFrame
DataFrame.columns
const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}]);
// Returns Seq ['x', 'y']
df.columns;
Returns the indexed Immutable.Seq of columns
pandas equivalent: DataFrame.columns
DataFrame.columns
const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}]);
df.columns = ['a', 'b'];
// Returns Seq ['a', 'b']
df.columns;
Sets columns
pandas equivalent: DataFrame.columns
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
columns | Next column names | None | Seq.Indexed. |
DataFrame.copy
const df = const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}]);
const df2 = df.copy();
df2.index = [1, 2, 3];
df.index // [0, 1, 2];
df2.index // [1, 2, 3];
Return a new deep copy of the DataFrame
pandas equivalent: DataFrame.copy
DataFrame.corr
const df = new DataFrame([{x: 1, y: 2, z: 3}, {x: 2, y: 1, z: 5}, {x: 3, y: 0, z: 7}]);
// Returns DataFrame([{x: 1, y: -1, z: 1}, {x: -1, y: 1, z: -1}, {x: 1, y: -1, z: 1}])
df.corr();
Calculate the correlation between all Series
in the DataFrame
pandas equivalent: DataFrame.corr
DataFrame.cov
const df = new DataFrame([{x: 1, y: 2, z: 3}, {x: 2, y: 1, z: 5}, {x: 3, y: 0, z: 7}]);
// Returns DataFrame([{x: 1, y: -1, z: 2}, {x: -1, y: 1, z: -2}, {x: 2, y: -2, z: 4}])
df.cov();
Calculate the covariance between all Series
in the DataFrame
pandas equivalent: DataFrame.cov
DataFrame.cummax
const ds = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}], {index: [2, 3, 4]});
// Returns DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}], {index: [2, 3, 4]});
ds.cummax();
// Returns DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}], {index: [2, 3 ,4]});
ds.cummax(1);
Return cumulative maximum over requested axis
pandas equivalent: DataFrame.cummax
DataFrame.cummin
const ds = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}], {index: [2, 3, 4]});
// Returns DataFrame([{x: 1, y: 1}, {x: 1, y: 1}, {x: 1, y: 1}], {index: [2, 3, 4]});
ds.cummin();
// Returns DataFrame([{x: 1, y: 1}, {x: 2, y: 2}, {x: 3, y: 3}], {index: [2, 3 ,4]});
ds.cummin(1);
Return cumulative minimum over requested axis
pandas equivalent: DataFrame.cummin
DataFrame.cummul
const ds = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}], {index: [2, 3, 4]});
// Returns DataFrame([{x: 1, y: 2}, {x: 2, y: 6}, {x: 6, y: 24}], {index: [2, 3, 4]});
ds.cummul();
// Returns DataFrame([{x: 1, y: 2}, {x: 2, y: 6}, {x: 3, y: 12}], {index: [2, 3 ,4]});
ds.cummul(1);
Return cumulative multiple over requested axis
pandas equivalent: DataFrame.cummul
DataFrame.cumsum
const ds = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}], {index: [2, 3, 4]});
// Returns DataFrame([{x: 1, y: 2}, {x: 3, y: 5}, {x: 6, y: 9}], {index: [2, 3, 4]});
ds.cumsum();
// Returns DataFrame([{x: 1, y: 3}, {x: 2, y: 5}, {x: 3, y: 7}], {index: [2, 3 ,4]});
ds.cumsum(1);
Return cumulative sum over requested axis
pandas equivalent: DataFrame.cumsum
DataFrame.diff
const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}]);
// Returns
// x | y
// 0 null | null
// 1 1 | 1
// 2 1 | 1
df.diff().toString();
Return the difference over a given number of periods along the axis
pandas equivalent: DataFrame.diff
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
periods | Number of periods to use for difference calculation | 1 | number |
axis | Axis along which to calculate difference | 0 | number |
Returns DataFrame
DataFrame.eq
const df = new DataFrame(Map({x: new Series([1, 2]), y: new Series([2, 3])}));
// Returns DataFrame(Map({x: Series([true, false]), y: Series([false, true])})
df.eq(new Series([1, 3]));
// Returns DataFrame(Map({x: Series([true, false]), y: Series([false, false])})
df.gt(new DataFrame(Map({
a: new Series([1, 1]),
b: new Series([1, 2])})));
Equal to DataFrame
and other, element wise
pandas equivalent: df == val
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
other | Other Iterable or scalar value to check for equal to | None | Array, List, Series, DataFrame, number, string |
Returns DataFrame
DataFrame.filter
const df = new DataFrame(Immutable.Map({x: new Series([1, 2]), y: new Series([2, 3])}));
// Returns DataFrame(Immutable.Map({x: Series([2]), y: Series([3]));
df.filter(df.get('x').gt(1));
// Returns DataFrame(Immutable.Map({x: Series([2]), y: Series([3]));
df.filter([false, true]);
// Returns DataFrame(Immutable.Map({x: Series([2]), y: Series([3]));
df.filter(Immutable.Map([false, true]));
Filter the DataFrame by an Iterable (Series, Array, or List) of booleans and return the subset
pandas equivalent: df[df condition]
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
iterBool | Iterable of booleans | None | Series, Array, List |
Returns DataFrame
DataFrame.get
const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}]);
// Returns Series([1, 2, 3], {name: 'x', index: [0, 1, 2]})
df.get('x');
// Returns DataFrame([{y: 2}, {y: 3}, {y: 4}])
df.get(['y']);
Return the Series
at the column
pandas equivalent: df['column_name']
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
columns | Name of the column to retrieve or list of columns to retrieve | None | string, Array. |
Returns Series
DataFrame.gt
const df = new DataFrame(Map({x: new Series([1, 2]), y: new Series([2, 3])}));
// Returns DataFrame(Map({x: Series([false, false]), y: Series([true, false])})
df.gt(new Series([1, 3]));
// Returns DataFrame(Map({x: Series([false, true]), y: Series([true, true])})
df.gt(new DataFrame(Map({
a: new Series([1, 1]),
b: new Series([1, 2])})));
Greater than of DataFrame
and other, element wise
pandas equivalent: df > val
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
other | Other Iterable or scalar value to check for greater than | None | Array, List, Series, DataFrame, number, string |
Returns DataFrame
DataFrame.gte
const df = new DataFrame(Map({x: new Series([1, 2]), y: new Series([2, 3])}));
// Returns DataFrame(Map({x: Series([true, false]), y: Series([true, true])})
df.gte(new Series([1, 3]));
// Returns DataFrame(Map({x: Series([true, true]), y: Series([true, true])})
df.gte(new DataFrame(Map({
a: new Series([1, 1]),
b: new Series([1, 2])})));
Greater than or equal to of DataFrame
and other, element wise
pandas equivalent: df >= val
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
other | Other Iterable or scalar value to check for greater than or equal to | None | Array, List, Series, DataFrame, number, string |
Returns DataFrame
DataFrame.head
const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}, {x: 4, y: 5}]);
// returns DataFrame([{x: 1, y: 2}, {x: 2, y: 3}])
df.head(2);
Return new DataFrame composed of first n rows of this DataFrame
pandas equivalent: DataFrame.head
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
n | Integer number of n rows to return from the DataFrame | 10 | number |
Returns DataFrame
DataFrame.iloc
const df = new DataFrame([{x: 1, y: 2, z: 3}, {x: 2, y: 3, z: 4}, {x: 3, y: 4, z: 5}]);
// Returns DataFrame([{y: 3}], {index: [1]})
df.iloc(1, 1);
// Returns DataFrame([{y: 3, z: 4}}], {index: [1]})
df.iloc(1, [1, 3]);
// Returns DataFrame([{y: 3, z: 4}, {y: 4, z: 5}], {index: [1, 2]})
df.iloc([1, 3], [1, 3]);
// Returns DataFrame([{y: 3}, {y: 4}], {index: [1, 2]})
df.iloc([1, 3], 1);
// Returns DataFrame([{y: 2}, {y: 3}, {y: 4}], {index: [0, 1, 2]})
df.iloc(1);
Return new DataFrame subset at [rowIdx, colIdx]
pandas equivalent: DataFrame.iloc
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
rowIdx | None | number, Array. |
|
colIdx | None | number, Array. |
Returns DataFrame
DataFrame.index
const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}]);
// Returns List [0, 1, 2, 3]
df.index;
Return the index values of the DataFrame
DataFrame.index
const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}]);
// Returns List [0, 1, 2, 3]
df.index;
df.index = Immutable.List([2, 3, 4, 5]);
// Returns List [2, 3, 4, 5]
df.index;
Set the index values of the DataFrame
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
index | Next index values | None | List, Array |
DataFrame.iterrows
const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}]);
// Logs 2 4 6
for(const [row, idx] of df) {
console.log(row.get('x') * 2);
}
A generator which returns [row, index location] tuples
pandas equivalent: DataFrame.iterrows
DataFrame.length
const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}]);
// Returns 3
df.length;
Return the length of the DataFrame
pandas equivalent: len(df);
DataFrame.lt
const df = new DataFrame(Map({x: new Series([1, 2]), y: new Series([2, 3])}));
// Returns DataFrame(Map({x: Series([false, true]), y: Series([false, false])})
df.lt(new Series([1, 3]));
// Returns DataFrame(Map({x: Series([false, false]), y: Series([false, false])})
df.lt(new DataFrame(Map({
a: new Series([1, 1]),
b: new Series([1, 2])})));
Less than of DataFrame
and other, element wise
pandas equivalent: df < val
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
other | Other Iterable or scalar value to check for less than | None | Array, List, Series, DataFrame, number, string |
Returns DataFrame
DataFrame.lte
const df = new DataFrame(Map({x: new Series([1, 2]), y: new Series([2, 3])}));
// Returns DataFrame(Map({x: Series([true, true]), y: Series([false, true])})
df.lte(new Series([1, 3]));
// Returns DataFrame(Map({x: Series([true, false]), y: Series([false, false])})
df.lte(new DataFrame(Map({
a: new Series([1, 1]),
b: new Series([1, 2])})));
Less than or equal to of DataFrame
and other, element wise
pandas equivalent: df <= val
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
other | Other Iterable or scalar value to check for less than or equal to | None | Array, List, Series, DataFrame, number, string |
Returns DataFrame
DataFrame.mean
const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}]);
// Returns
// x 2
// y 3
// Name: , dtype: dtype('int')
df.mean().toString();
const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}]);
// Returns
// 0 1.5
// 1 2.5
// 2 3.5
// Name: , dtype: dtype('float')
df.mean(1).toString();
Return the mean of the values in the DataFrame
along the axis
pandas equivalent: DataFrame.mean
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
axis | Axis along which to average values | 0 | number |
Returns Series
DataFrame.merge
const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}]);
const df2 = new DataFrame([{x: 1, z: 3}, {x: 3, z: 5}, {x: 2, z: 10}]);
// Returns
// x | y | z
// 0 1 | 2 | 3
// 1 2 | 3 | 10
// 2 3 | 4 | 5
df.merge(df2, ['x'], 'inner');
Merge this DataFrame
with another DataFrame
, optionally on some set of columns
pandas equivalent: DataFrame.merge
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
df | DataFrame with which to merge this DataFrame |
None | DataFrame |
on | Array of columns on which to merge | None | Array |
how | Merge method, either 'inner' or 'outer' | 'inner' | string |
Returns DataFrame
DataFrame.pct_change
const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}]);
// Returns
// x | y
// 0 null | null
// 1 1 | 0.5
// 2 0.5 | 0.3333
df.pct_change().toString();
Return the percentage change over a given number of periods along the axis
pandas equivalent: DataFrame.pct_change
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
periods | Number of periods to use for percentage change calculation | 1 | number |
axis | Axis along which to calculate percentage change | 0 | number |
Returns DataFrame
DataFrame.pivot
Reshape data (produce a 'pivot' table) based on column values. Uses unique values from index / columns to form axes of the resulting DataFrame.
pandas equivalent: DataFrame.pivot
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
index | Name of the column to use as index | None | string, number |
columns | Name of the column to use as column values | None | string, number |
values | Name of the column to use as the value | None | string, number |
Returns DataFrame
DataFrame.pivot_table
Reshape data (produce a 'pivot' table) based on a set of index, columns, or values columns from the original DataFrame
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
index | Name(s) of column(s) to use as the index for the pivoted DataFrame | None | Array. |
columns | Name(s) of column(s) to use as the columns for the pivoted DataFrame | None | Array. |
values | Name(s) of column(s) to use as the values for the pivoted DataFrame | None | Array. |
aggfunc | Name of aggregation function | sum | string |
DataFrame.rename
Rename the DataFrame
and return a new DataFrame
pandas equivalent: DataFrame.rename
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
columns | None | Immutable.Map |
Returns DataFrame
DataFrame.reset_index
const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}], {index: [1, 2]});
// returns DataFrame([{index: 1, x: 1, y: 2}, {index: 2, x: 2, y: 3}], {index: [0, 1]})
df.reset_index();
// returns DataFrame([{x: 1, y: 2}, {x: 2, y: 3}], {index: [0, 1]});
df.reset_index({drop: true});
const df2 = new DataFrame([{index: 1}, {index: 2}], {index: [1, 2]});
// returns DataFrame([{level_0: 1, index: 1}, {level_0: 1, index: 2}], {index: [1, 2]});
df2.reset_index();
Reset the index for a DataFrame
pandas equivalent: DataFrame.reset_index
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
args | None | object | |
args.drop | Drop the index when resetting? Otherwise, add as new column | None | boolean |
Returns DataFrame
DataFrame.set
const df = new DataFrame([{x: 1}, {x: 2}, {x: 3}]);
// Returns DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}]);
df.set('y', new Series([2, 3, 4]));
Set a Series
at column
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
column | None | string, number | |
series | None | Series, List, Array |
Returns DataFrame
DataFrame.std
const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}]);
// Returns
// x 1
// y 1
// Name: , dtype: dtype('int')
df.std().toString();
const df = new DataFrame([{x: 1, y: 1}, {x: 2, y: 2}, {x: 3, y: 3}]);
// Returns
// 0 0
// 1 0
// 2 0
// Name: , dtype: dtype('int')
df.std(1).toString();
Return the standard deviation of the values in the DataFrame
along the axis
pandas equivalent: DataFrame.std
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
axis | Axis along which to calculate the standard deviation | 0 | number |
Returns Series
DataFrame.sum
const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}]);
// Returns
// x 6
// y 9
// Name: , dtype: dtype(int)
df.sum().toString();
const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}]);
// Returns
// 0 3
// 1 5
// 2 7
// Name: , dtype: dtype('int')
df.sum(1).toString();
Return the sum of the values in the DataFrame
along the axis
pandas equivalent: DataFrame.sum
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
axis | Axis along which to sum values | 0 | number |
Returns Series
DataFrame.tail
const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}, {x: 4, y: 5}]);
// returns DataFrame([{x: 3, y: 4}, {x: 4, y: 5}])
df.tail(2);
Return new DataFrame composed of last n rows of this DataFrame
pandas equivalent: DataFrame.tail
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
n | Integer number of n rows to return from the DataFrame | 10 | number |
Returns DataFrame
DataFrame.to_csv
const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}]);
// Returns x,y,\r\n1,2,\r\n2,3\r\n3,4\r\n
df.to_csv();
Convert the DataFrame
to a csv string
pandas equivalent: DataFrame.to_csv
DataFrame.to_excel
Write the DataFrame
to a Workbook object
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
excel_writer | File path or existing Workbook object | None | string, Workbook |
sheetName | Name of values which will contain DataFrame | Sheet1 | string |
download | Download the excel file? | False | boolean |
kwargs | None | Object | |
kwargs.index | True | boolean |
Returns Workbook
DataFrame.to_json
const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}]);
// Returns {x: {0: 1, 1: 2, 2: 3}, y: {0: 1, 1: 2, 2: 3}}
df.to_json();
// Returns [{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}]
df.to_json({orient: 'records'});
// Returns {0: {x: 1, y: 2}, 1: {x: 2, y: 3}, 2: {x: 3, y: 4}}
df.to_json({orient: 'index'});
// Returns {index: [0, 1, 2], columns: ['x', 'y'], values: [[1, 2], [2, 3], [3, 4]]}
df.to_json({orient: 'split'});
// Returns [[1, 2], [2, 3], [3, 4]]
df.to_json({orient: 'values'});
Convert the DataFrame to a json object
pandas equivalent: DataFrame.to_json
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
kwargs | None | None | |
kwargs.orient | orientation of JSON | columns | string |
Returns *
DataFrame.transpose
const df1 = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}], {index: [1, 2, 3]});
// Returns DataFrame(
[{1: 1, 2: 2, 3: 3}, {1: 2, 2: 3, 3: 4}], {index: ['x', 'y']});
df1.transpose();
Transpose the DataFrame by switching the index and columns
pandas equivalent: DataFrame.transpose
DataFrame.values
const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}]);
// Returns List [ List[1, 2, 3], List[2, 3, 4]]
df.values;
Immutable.List of Immutable.List, with [row][column] indexing
pandas equivalent: DataFrame.values
DataFrame.variance
const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 3, y: 4}]);
// Returns
// x 1
// y 1
// Name: , dtype: dtype('int')
df.std().toString();
const df = new DataFrame([{x: 1, y: 1}, {x: 2, y: 2}, {x: 3, y: 3}]);
// Returns
// 0 0
// 1 0
// 2 0
// Name: , dtype: dtype('int')
df.std(1).toString();
Return the variance of the values in the DataFrame
along the axis
pandas equivalent: DataFrame.var
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
axis | Axis along which to calculate the variance | 0 | number |
Returns Series
DataFrame.where
const df = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}]);
// Returns DataFrame(Map({x: Series([true, false]), y: Series([false, true])})
df.where(new Series([1, 3]), (a, b) => a === b);
// Returns DataFrame(Map({x: Series([true, false]), y: Series([false, true])})
df.where(new DataFrame(Map({
a: new Series([1, 1]),
b: new Series([3, 3])})),
(a, b) => a === b);
Return an object of same shape as self and whose corresponding entries are from self where cond is True and otherwise are from other.
pandas equivalent DataFrame.where
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
other | Iterable or value to compare to DataFrame | None | Array, List, Series, DataFrame, number, string |
op | Function which takes (a, b) values and returns a boolean | None | function |
Returns DataFrame
Utilities
concat
const series1 = new Series([1, 2, 3, 4]);
const series2 = new Series([2, 3, 4, 5]);
// Returns Series([1, 2, 3, 4, 2, 3, 4, 5], {index: [0, 1, 2, 3, 0, 1, 2, 3]})
concat([series1, series2], {ignore_index: false});
// Returns Series([1, 2, 3, 4, 2, 3, 4, 5], {index: [0, 1, 2, 3, 4, 5, 6, 7]})
concat([series1, series2], {ignore_index: true});
const df1 = new DataFrame([{x: 1, y: 2}, {x: 2, y: 3}], {index: [1, 2]});
const df2 = new DataFrame([{x: 2, y: 2}, {x: 3, y: 3}], {index: [2, 3]});
// Returns DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 2, y: 2}, {x: 3, y: 3}], {index: [1, 2, 2, 3]})
concat([df1, df2]);
// Returns DataFrame([{x: 1, y: 2}, {x: 2, y: 3}, {x: 2, y: 2}, {x: 3, y: 3}], {index: [0, 1, 2, 3]})
concat([df1, df2], {ignore_index: true});
Concatenate pandas objects along a particular axis.
Parameters
Name | Description | Default | Type(s) |
---|---|---|---|
objs | Objects to be concatenated | None | Array, Immutable.List |
kwargs | Extra optional arguments for concat | None | Object |
kwargs.ignore_index | Ignore the indices when concatenating | false |
boolean |
kwargs.axis | Axis along which to concatenate DataFrame s |
0 | number |