pandas-tspandas-ts
npm

API reference

Series

A one-dimensional labeled array capable of holding any data type. The axis labels are collectively referred to as the index.

NameSummary
new SeriesConstruct a Series. data can be an array, object, typed array, or another Seri
Series#sizeReturn the number of elements in the Series.
Series#dtypeReturn the dtype of the underlying data.
Series#meanReturn the mean of the values, excluding NaN by default.
Series#stdReturn the sample standard deviation (ddof=1 by default).
Series#sumReturn the sum of the values.
Series#minReturn the minimum value.
Series#maxReturn the maximum value.
Series#medianReturn the median of the values.
Series#quantileReturn value at the given quantile (0–1).
Series#headReturn the first n rows. Default n is 5.
Series#tailReturn the last n rows. Default n is 5.
Series#ilocPurely integer-location based indexing for selection by position.
Series#locAccess a group of rows and columns by label(s).
Series#fillnaFill NA/NaN values with the specified value or method.
Series#dropnaReturn a new Series with missing values removed.
Series#sort_valuesSort by the values.
Series#value_countsReturn a Series containing counts of unique values, sorted by frequency.
Series#applyApply a function element-wise.
Series#mapMap values using an input correspondence or function.
Series#groupbyGroup the Series using a mapper or by a Series of values.
Series#rollingProvide rolling window calculations.
Series#cumsumReturn cumulative sum.
Series#diffFirst discrete difference of element.
Series#corrCompute Pearson correlation with another Series.
Series#addElement-wise addition. other can be a scalar or another Series.
Series#subElement-wise subtraction.
Series#mulElement-wise multiplication.
Series#divElement-wise true division.
Series#powElement-wise exponentiation.
Series#absReturn Series with absolute numeric value of each element.
Series#roundRound each value to the given number of decimals.
Series#clipTrim values at input threshold(s).
Series#uniqueReturn unique values as an array.
Series#nuniqueReturn the number of unique elements in the Series.
Series#isnaDetect missing values. Returns a boolean Series.
Series#notnaDetect existing (non-missing) values.
Series#describeGenerate descriptive statistics: count, mean, std, min, 25%, 50%, 75%, max.
Series#to_listReturn the Series as a plain JavaScript array.
Series#normCompute vector norm (powered by @cyfora/numera). Default L2 norm.
Series#histCompute histogram (powered by @cyfora/numera). Returns bin counts and edges.
Series#percentileReturn value at the given percentile (0–100 scale), powered by @cyfora/numera.
Series#interpOne-dimensional linear interpolation (powered by @cyfora/numera). Treats the Ser
Series#at_timeSelect values at a particular time of day from a datetime-indexed Series. time
Series#between_timeSelect values between two times of day from a datetime-indexed Series. Both argu
Series#tz_convertConvert a datetime Series to a different timezone. Uses Intl.DateTimeFormat to
Series#tz_localizeAttach timezone metadata to a naive datetime Series. Passing null strips the t
Series#unstackPivot a MultiIndex (tuple) index level into columns, producing a DataFrame-like

new Series

#
new Series(data, options?)

Construct a Series. data can be an array, object, typed array, or another Series. options.index sets the index labels; options.name names the Series; options.dtype overrides dtype inference.

Parameters

dataunknown[] | TypedArray | Record<string, unknown>
The data for the Series.
options?{ index?, name?, dtype? }
Construction options.

Returns

Series

Example

TypeScript
import { Series } from 'pandas-ts';
const s = new Series([1, 2, 3, 4, 5], { name: 'numbers' });
s.mean();    // => 3
s.std();     // => 1.5811388300841898

Series#size

#
s.size

Return the number of elements in the Series.

Returns

number

Example

TypeScript
const s = new Series([10, 20, 30]);
s.size;    // => 3

Series#dtype

#
s.dtype

Return the dtype of the underlying data.

Returns

DType

Example

TypeScript
new Series([1, 2, 3]).dtype.name;        // => 'int64'
new Series([1.5, 2.5]).dtype.name;      // => 'float64'
new Series(['a', 'b']).dtype.name;      // => 'object'

Series#mean

#
s.mean(options?)

Return the mean of the values, excluding NaN by default.

Returns

number

Example

TypeScript
new Series([1, 2, 3, 4, 5]).mean();    // => 3

Series#std

#
s.std(options?)

Return the sample standard deviation (ddof=1 by default).

Returns

number

Example

TypeScript
new Series([1, 2, 3, 4, 5]).std();    // => 1.5811388300841898

Series#sum

#
s.sum()

Return the sum of the values.

Returns

number

Example

TypeScript
new Series([1, 2, 3, 4, 5]).sum();    // => 15

Series#min

#
s.min()

Return the minimum value.

Returns

unknown

Example

TypeScript
new Series([3, 1, 2]).min();    // => 1

Series#max

#
s.max()

Return the maximum value.

Returns

unknown

Example

TypeScript
new Series([3, 1, 2]).max();    // => 3

Series#median

#
s.median()

Return the median of the values.

Returns

number

Example

TypeScript
new Series([1, 3, 2]).median();    // => 2

Series#quantile

#
s.quantile(q)

Return value at the given quantile (0–1).

Parameters

qnumber
Quantile between 0 and 1.

Returns

number

Example

TypeScript
new Series([1, 2, 3, 4, 5]).quantile(0.5);    // => 3

Series#head

#
s.head(n?)

Return the first n rows. Default n is 5.

Returns

Series

Example

TypeScript
new Series([1,2,3,4,5,6]).head(3).to_list();    // => [1, 2, 3]

Series#tail

#
s.tail(n?)

Return the last n rows. Default n is 5.

Returns

Series

Example

TypeScript
new Series([1,2,3,4,5,6]).tail(3).to_list();    // => [4, 5, 6]

Series#iloc

#
s.iloc(i)

Purely integer-location based indexing for selection by position.

Returns

unknown

Example

TypeScript
const s = new Series([10, 20, 30], { index: ['a', 'b', 'c'] });
s.iloc(1);    // => 20

Series#loc

#
s.loc(label)

Access a group of rows and columns by label(s).

Returns

unknown

Example

TypeScript
const s = new Series([10, 20, 30], { index: ['a', 'b', 'c'] });
s.loc('b');    // => 20

Series#fillna

#
s.fillna(value)

Fill NA/NaN values with the specified value or method.

Returns

Series

Example

TypeScript
import { Series } from 'pandas-ts';
const s = new Series([1, NaN, 3]);
s.fillna(0).to_list();    // => [1, 0, 3]

Series#dropna

#
s.dropna()

Return a new Series with missing values removed.

Returns

Series

Example

TypeScript
new Series([1, NaN, 3]).dropna().to_list();    // => [1, 3]

Series#sort_values

#
s.sort_values(options?)

Sort by the values.

Returns

Series

Example

TypeScript
new Series([3,1,2]).sort_values().to_list();    // => [1, 2, 3]

Series#value_counts

#
s.value_counts(options?)

Return a Series containing counts of unique values, sorted by frequency.

Returns

Series

Example

TypeScript
new Series(['a','b','a','c','b','b']).value_counts().to_list();    // => [3, 2, 1]

Series#apply

#
s.apply(fn)

Apply a function element-wise.

Returns

Series

Example

TypeScript
new Series([1, 2, 3]).apply(x => x ** 2).to_list();    // => [1, 4, 9]

Series#map

#
s.map(mapping)

Map values using an input correspondence or function.

Returns

Series

Example

TypeScript
new Series(['a','b','c']).map({ a: 1, b: 2, c: 3 }).to_list();    // => [1, 2, 3]

Series#groupby

#
s.groupby(by)

Group the Series using a mapper or by a Series of values.

Returns

SeriesGroupBy

Example

TypeScript
const s = new Series([1, 2, 3, 4], { index: ['a','b','a','b'] });
s.groupby(s.index).sum().to_list();    // => [4, 6]

Series#rolling

#
s.rolling(window)

Provide rolling window calculations.

Returns

RollingWindow

Example

TypeScript
new Series([1,2,3,4,5]).rolling(3).mean().to_list();    // => [NaN, NaN, 2, 3, 4]

Series#cumsum

#
s.cumsum()

Return cumulative sum.

Returns

Series

Example

TypeScript
new Series([1, 2, 3]).cumsum().to_list();    // => [1, 3, 6]

Series#diff

#
s.diff(periods?)

First discrete difference of element.

Returns

Series

Example

TypeScript
new Series([1, 3, 6, 10]).diff().to_list();    // => [NaN, 2, 3, 4]

Series#corr

#
s.corr(other)

Compute Pearson correlation with another Series.

Returns

number

Example

TypeScript
const a = new Series([1,2,3,4,5]);
const b = new Series([2,4,6,8,10]);
a.corr(b);    // => 1

Series#add

#
s.add(other)

Element-wise addition. other can be a scalar or another Series.

Returns

Series

Example

TypeScript
new Series([1, 2, 3]).add(10).to_list();    // => [11, 12, 13]
new Series([1, 2, 3]).add(new Series([4, 5, 6])).to_list();    // => [5, 7, 9]

Series#sub

#
s.sub(other)

Element-wise subtraction.

Returns

Series

Example

TypeScript
new Series([10, 20, 30]).sub(5).to_list();    // => [5, 15, 25]

Series#mul

#
s.mul(other)

Element-wise multiplication.

Returns

Series

Example

TypeScript
new Series([1, 2, 3]).mul(3).to_list();    // => [3, 6, 9]

Series#div

#
s.div(other)

Element-wise true division.

Returns

Series

Example

TypeScript
new Series([10, 20, 30]).div(2).to_list();    // => [5, 10, 15]

Series#pow

#
s.pow(exp)

Element-wise exponentiation.

Returns

Series

Example

TypeScript
new Series([2, 3, 4]).pow(2).to_list();    // => [4, 9, 16]

Series#abs

#
s.abs()

Return Series with absolute numeric value of each element.

Returns

Series

Example

TypeScript
new Series([-1, 2, -3]).abs().to_list();    // => [1, 2, 3]

Series#round

#
s.round(decimals?)

Round each value to the given number of decimals.

Returns

Series

Example

TypeScript
new Series([1.234, 5.678]).round(2).to_list();    // => [1.23, 5.68]

Series#clip

#
s.clip(lower?, upper?)

Trim values at input threshold(s).

Returns

Series

Example

TypeScript
new Series([1, 5, 10, 15]).clip(3, 12).to_list();    // => [3, 5, 10, 12]

Series#unique

#
s.unique()

Return unique values as an array.

Returns

unknown[]

Example

TypeScript
new Series([1, 2, 2, 3, 3, 3]).unique();    // => [1, 2, 3]

Series#nunique

#
s.nunique()

Return the number of unique elements in the Series.

Returns

number

Example

TypeScript
new Series([1, 2, 2, 3]).nunique();    // => 3

Series#isna

#
s.isna()

Detect missing values. Returns a boolean Series.

Returns

Series

Example

TypeScript
new Series([1, NaN, null, 4]).isna().to_list();    // => [false, true, true, false]

Series#notna

#
s.notna()

Detect existing (non-missing) values.

Returns

Series

Example

TypeScript
new Series([1, NaN, 3]).notna().to_list();    // => [true, false, true]

Series#describe

#
s.describe()

Generate descriptive statistics: count, mean, std, min, 25%, 50%, 75%, max.

Returns

Series

Example

TypeScript
new Series([1,2,3,4,5]).describe().index;
// => ['count','mean','std','min','25%','50%','75%','max']

Series#to_list

#
s.to_list()

Return the Series as a plain JavaScript array.

Returns

unknown[]

Example

TypeScript
new Series([1, 2, 3]).to_list();    // => [1, 2, 3]

Series#norm

#
s.norm(ord?)

Compute vector norm (powered by @cyfora/numera). Default L2 norm.

Parameters

ordnumber
Order of the norm. Default 2.

Returns

number

Example

TypeScript
new Series([3, 4]).norm();    // => 5

Series#hist

#
s.hist(bins?, options?)

Compute histogram (powered by @cyfora/numera). Returns bin counts and edges.

Returns

{ hist: number[], edges: number[] }

Example

TypeScript
const { hist, edges } = new Series([1,2,2,3,3,3]).hist(3);
hist;     // => [1, 2, 3]
edges.length;    // => 4

Series#percentile

#
s.percentile(q)

Return value at the given percentile (0–100 scale), powered by @cyfora/numera.

Returns

number

Example

TypeScript
new Series([1,2,3,4,5]).percentile(50);    // => 3

Series#interp

#
s.interp(xp, fp)

One-dimensional linear interpolation (powered by @cyfora/numera). Treats the Series values as x-coordinates.

Returns

Series

Example

TypeScript
new Series([0, 1, 2]).interp([0, 1, 2], [0, 10, 20]).to_list();    // => [0, 10, 20]

Series#at_time

#
s.at_time(time)

Select values at a particular time of day from a datetime-indexed Series. time is a string in 'HH:MM' format.

Returns

Series

Example

TypeScript
const dates = [new Date('2024-01-01T09:00:00'), new Date('2024-01-01T12:00:00')];
const s = new Series([10, 20], { index: dates });
s.at_time('09:00').to_list();    // => [10]

Series#between_time

#
s.between_time(start_time, end_time)

Select values between two times of day from a datetime-indexed Series. Both arguments are 'HH:MM' strings. Handles midnight wrap-around.

Returns

Series

Example

TypeScript
s.between_time('08:00', '10:00').to_list();    // values in that time window

Series#tz_convert

#
s.tz_convert(tz)

Convert a datetime Series to a different timezone. Uses Intl.DateTimeFormat to re-express each Date value in the target timezone.

Returns

Series

Example

TypeScript
const s = new Series([new Date('2024-06-01T15:00:00Z')]);
s.tz_convert('America/New_York').iloc(0).getHours();    // => 11

Series#tz_localize

#
s.tz_localize(tz)

Attach timezone metadata to a naive datetime Series. Passing null strips the timezone. The return value carries a _tz property.

Returns

Series

Example

TypeScript
const s = new Series([new Date('2024-01-01T12:00:00')]);
const loc = s.tz_localize('UTC');

Series#unstack

#
s.unstack(level?)

Pivot a MultiIndex (tuple) index level into columns, producing a DataFrame-like object. level defaults to -1 (innermost).

Returns

DataFrame-like

Example

TypeScript
const s = new Series([1,2,3,4], { index: [['a',0],['a',1],['b',0],['b',1]] });
const df = s.unstack();    // columns: [0, 1], index: ['a', 'b']