API reference
Series
A one-dimensional labeled array capable of holding any data type. The axis labels are collectively referred to as the index.
| Name | Summary |
|---|---|
new Series | Construct a Series. data can be an array, object, typed array, or another Seri |
Series#size | Return the number of elements in the Series. |
Series#dtype | Return the dtype of the underlying data. |
Series#mean | Return the mean of the values, excluding NaN by default. |
Series#std | Return the sample standard deviation (ddof=1 by default). |
Series#sum | Return the sum of the values. |
Series#min | Return the minimum value. |
Series#max | Return the maximum value. |
Series#median | Return the median of the values. |
Series#quantile | Return value at the given quantile (0–1). |
Series#head | Return the first n rows. Default n is 5. |
Series#tail | Return the last n rows. Default n is 5. |
Series#iloc | Purely integer-location based indexing for selection by position. |
Series#loc | Access a group of rows and columns by label(s). |
Series#fillna | Fill NA/NaN values with the specified value or method. |
Series#dropna | Return a new Series with missing values removed. |
Series#sort_values | Sort by the values. |
Series#value_counts | Return a Series containing counts of unique values, sorted by frequency. |
Series#apply | Apply a function element-wise. |
Series#map | Map values using an input correspondence or function. |
Series#groupby | Group the Series using a mapper or by a Series of values. |
Series#rolling | Provide rolling window calculations. |
Series#cumsum | Return cumulative sum. |
Series#diff | First discrete difference of element. |
Series#corr | Compute Pearson correlation with another Series. |
Series#add | Element-wise addition. other can be a scalar or another Series. |
Series#sub | Element-wise subtraction. |
Series#mul | Element-wise multiplication. |
Series#div | Element-wise true division. |
Series#pow | Element-wise exponentiation. |
Series#abs | Return Series with absolute numeric value of each element. |
Series#round | Round each value to the given number of decimals. |
Series#clip | Trim values at input threshold(s). |
Series#unique | Return unique values as an array. |
Series#nunique | Return the number of unique elements in the Series. |
Series#isna | Detect missing values. Returns a boolean Series. |
Series#notna | Detect existing (non-missing) values. |
Series#describe | Generate descriptive statistics: count, mean, std, min, 25%, 50%, 75%, max. |
Series#to_list | Return the Series as a plain JavaScript array. |
Series#norm | Compute vector norm (powered by @cyfora/numera). Default L2 norm. |
Series#hist | Compute histogram (powered by @cyfora/numera). Returns bin counts and edges. |
Series#percentile | Return value at the given percentile (0–100 scale), powered by @cyfora/numera. |
Series#interp | One-dimensional linear interpolation (powered by @cyfora/numera). Treats the Ser |
Series#at_time | Select values at a particular time of day from a datetime-indexed Series. time |
Series#between_time | Select values between two times of day from a datetime-indexed Series. Both argu |
Series#tz_convert | Convert a datetime Series to a different timezone. Uses Intl.DateTimeFormat to |
Series#tz_localize | Attach timezone metadata to a naive datetime Series. Passing null strips the t |
Series#unstack | Pivot 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
import { Series } from 'pandas-ts';
const s = new Series([1, 2, 3, 4, 5], { name: 'numbers' });
s.mean(); // => 3
s.std(); // => 1.5811388300841898Series#size
#s.size
Return the number of elements in the Series.
Returns
number
Example
const s = new Series([10, 20, 30]);
s.size; // => 3Series#dtype
#s.dtype
Return the dtype of the underlying data.
Returns
DType
Example
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
new Series([1, 2, 3, 4, 5]).mean(); // => 3Series#std
#s.std(options?)
Return the sample standard deviation (ddof=1 by default).
Returns
number
Example
new Series([1, 2, 3, 4, 5]).std(); // => 1.5811388300841898Series#sum
#s.sum()
Return the sum of the values.
Returns
number
Example
new Series([1, 2, 3, 4, 5]).sum(); // => 15Series#min
#s.min()
Return the minimum value.
Returns
unknown
Example
new Series([3, 1, 2]).min(); // => 1Series#max
#s.max()
Return the maximum value.
Returns
unknown
Example
new Series([3, 1, 2]).max(); // => 3Series#median
#s.median()
Return the median of the values.
Returns
number
Example
new Series([1, 3, 2]).median(); // => 2Series#quantile
#s.quantile(q)
Return value at the given quantile (0–1).
Parameters
qnumber- Quantile between 0 and 1.
Returns
number
Example
new Series([1, 2, 3, 4, 5]).quantile(0.5); // => 3Series#head
#s.head(n?)
Return the first n rows. Default n is 5.
Returns
Series
Example
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
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
const s = new Series([10, 20, 30], { index: ['a', 'b', 'c'] });
s.iloc(1); // => 20Series#loc
#s.loc(label)
Access a group of rows and columns by label(s).
Returns
unknown
Example
const s = new Series([10, 20, 30], { index: ['a', 'b', 'c'] });
s.loc('b'); // => 20Series#fillna
#s.fillna(value)
Fill NA/NaN values with the specified value or method.
Returns
Series
Example
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
new Series([1, NaN, 3]).dropna().to_list(); // => [1, 3]Series#sort_values
#s.sort_values(options?)
Sort by the values.
Returns
Series
Example
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
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
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
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
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
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
new Series([1, 2, 3]).cumsum().to_list(); // => [1, 3, 6]Series#diff
#s.diff(periods?)
First discrete difference of element.
Returns
Series
Example
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
const a = new Series([1,2,3,4,5]);
const b = new Series([2,4,6,8,10]);
a.corr(b); // => 1Series#add
#s.add(other)
Element-wise addition. other can be a scalar or another Series.
Returns
Series
Example
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
new Series([10, 20, 30]).sub(5).to_list(); // => [5, 15, 25]Series#mul
#s.mul(other)
Element-wise multiplication.
Returns
Series
Example
new Series([1, 2, 3]).mul(3).to_list(); // => [3, 6, 9]Series#div
#s.div(other)
Element-wise true division.
Returns
Series
Example
new Series([10, 20, 30]).div(2).to_list(); // => [5, 10, 15]Series#pow
#s.pow(exp)
Element-wise exponentiation.
Returns
Series
Example
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
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
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
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
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
new Series([1, 2, 2, 3]).nunique(); // => 3Series#isna
#s.isna()
Detect missing values. Returns a boolean Series.
Returns
Series
Example
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
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
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
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
new Series([3, 4]).norm(); // => 5Series#hist
#s.hist(bins?, options?)
Compute histogram (powered by @cyfora/numera). Returns bin counts and edges.
Returns
{ hist: number[], edges: number[] }
Example
const { hist, edges } = new Series([1,2,2,3,3,3]).hist(3);
hist; // => [1, 2, 3]
edges.length; // => 4Series#percentile
#s.percentile(q)
Return value at the given percentile (0–100 scale), powered by @cyfora/numera.
Returns
number
Example
new Series([1,2,3,4,5]).percentile(50); // => 3Series#interp
#s.interp(xp, fp)
One-dimensional linear interpolation (powered by @cyfora/numera). Treats the Series values as x-coordinates.
Returns
Series
Example
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
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
s.between_time('08:00', '10:00').to_list(); // values in that time windowSeries#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
const s = new Series([new Date('2024-06-01T15:00:00Z')]);
s.tz_convert('America/New_York').iloc(0).getHours(); // => 11Series#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
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
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']