Data manipulation and analysis library written in JavaScript offering the convenience of pandas or R.
Methods
(static) addCol(col, arr, dataframe) → {df}
Add a new column to a dataframe from an array.
Use this function to add an array as a new column in a dataframe. Make sure the array has the same length as the number of rows in the dataframe.
Example
const df = [{"label": "A", "value": 7}, {"label": "B", "value": 2}]
const series = ["2010-12-15", "2010-12-16"]
Z.addCol("date", series, df)
// [{"date": "2010-12-15", "label": "A", "value": 7}, {"date": "2010-12-16", "label": "B", "value": 2}]
Parameters:
Name | Type | Description |
---|---|---|
col |
String | Name of the column do add |
arr |
Array | Array of values for the new column |
dataframe |
df | Zebras dataframe to add the new column to |
Returns:
- Type
- df
(static) concat(dataframe1, dataframe2) → {df}
Concatenate two dataframes.
Example
const df1 = [{"label": "A", "value": 7}, {"label": "B", "value": 2}]
const df2 = [{"label": "C", "value": 17}, {"label": "D", "value": 2}]
Z.concat(df1, df2)
// [{"label": "A", "value": 7}, {"label": "B", "value": 2}, {"label": "C", "value": 17}, {"label": "D", "value": 2}]
Parameters:
Name | Type | Description |
---|---|---|
dataframe1 |
df | Zebras dataframe |
dataframe2 |
df | Zebras dataframe |
Returns:
Zebras dataframe
- Type
- df
(static) corr(series1, series2) → {Number}
Correlation between two series.
Example
const series1 = [10, 15, 20, 25, 50, 55]
const series2 = [12, 18, 34, 52, 71, 86]
Z.corr(series1, series2)
// 0.969035563335365
Parameters:
Name | Type | Description |
---|---|---|
series1 |
Array | First series |
series2 |
Array | Second series |
Returns:
- Type
- Number
(static) countUnique(arr) → {Number}
- Source:
Count number of unique values in a series.
Example
const series = [7, 2, 30, 30, 56, 75]
Z.countUnique(series)
// 5
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | Array of values |
Returns:
- Type
- Number
(static) cumulative(func, arr) → {Array}
- Source:
Calculate cumulative statistics.
Calculate statistics over a cumulative window from the start of the array. Works wtih z.min, z.max, z.mean, z.std, z.sum, z.prod, etc., or any other function that takes an array as a single argument.
Example
const series = [7, 2, 30, 30, 56, 75]
Z.cumulative(Z.mean, series)
// [7, 4.5, 13, 17.25, 25, 33.333333333333336]
Parameters:
Name | Type | Description |
---|---|---|
func |
function | Function to caclulate cumulative statistics |
arr |
Array | Series to calculate cumulative statistics for |
Returns:
- Type
- Array
(static) deriveCol(func, dataframe) → {Array}
- Source:
Create a new array based on columns from existing dataframe.
Use to create new columns derived from existing columns in a dataframe.
Example
const temps = [{"date": "1990-05-06", "tempCelsius": 0}, {"date": "1990-05-07", "tempCelsius": 4}]
const fahrenheit = Z.deriveCol((r) => r.tempCelsius * 1.8 + 32, temps)
Z.addCol("tempFahrenheit", fahrenheit, temps)
// [{"date": "1990-05-06", "tempCelsius": 0, "tempFahrenheit": 32}, {"date": "1990-05-07", "tempCelsius": 4, "tempFahrenheit": 39.2}]
Parameters:
Name | Type | Description |
---|---|---|
func |
function | Function to create the new column |
dataframe |
df | Zebras dataframe to add the new column to |
Returns:
- Type
- Array
(static) describe(func, arr) → {Number}
- Source:
Calculate summary statistics for a numerical series.
Returns a single-row df with count, unique count, min, max, median, mean and standard deviation of a numerical series.
Example
const series = [7, 2, 30, 30, 56, 75]
Z.describe(series)
// [{"count": 6, "countUnique": 5, "max": "75.00000", "mean": "33.33333", "median": "30.00000", "min": "2.00000", "std": "28.09745"}]
Parameters:
Name | Type | Description |
---|---|---|
func |
function | Function to caclulate cumulative statistics |
arr |
Array | Series to calculate cumulative statistics for |
Returns:
- Type
- Number
(static) diff(arr) → {Array}
Returns a new series with the differences between the values in the order of the input series.
Example
const series = [7, 2, 30, 30, 56, 75]
Z.diff(series)
// [NaN, -5, 28, 0, 26, 19]
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | Series to calculate differences for |
Returns:
- Type
- Array
(static) dropCol(col, dataframe) → {df}
- Source:
Delete a column.
Example
const df = [{"label": "A", "value": 7}, {"label": "B", "value": 2}, {"label": "C", "value": 75}]
Z.dropCol("label", df)
// [{"value": 7}, {"value": 2}, {"value": 75}]
Parameters:
Name | Type | Description |
---|---|---|
col |
String | Name of the column to delete |
dataframe |
df | Zebras dataframe |
Returns:
Zebras dataframe
- Type
- df
(static) fFill(df, cols) → {df}
Front fill a dataframe
Returns the dataframes with NaN or null values filled in. Does not treat 0 as something to fill in, but does treat "" as such
Example
const series = [{"label": "A", "value": 7}, {"label": "B", "value": NaN}, {"label": "C", "value": 75}]
Z.fFill(series)
// [{"label": "A", "value": 7}, {"label": "B", "value": 7}, {"label": "C", "value": 75}]
Parameters:
Name | Type | Description |
---|---|---|
df |
df | Series to front fill |
cols |
Array | Array of column names to convert. Set to null or [] for all. |
Returns:
- Type
- df
(static) fillNA(df, fillValue, cols) → {df}
Front fill a dataframe
Returns the dataframes with NaN or null values filled in. Does not treat 0 as something to fill in, but does treat "" as such
Example
const series = [{"label": "A", "value": 7}, {"label": "B", "value": NaN}, {"label": "C", "value": 75}]
Z.fillNA(series, -1)
// [{"label": "A", "value": 7}, {"label": "B", "value": -1}, {"label": "C", "value": 75}]
Parameters:
Name | Type | Description |
---|---|---|
df |
df | Dataframe to fill NAs |
fillValue |
any | Value to fill with |
cols |
Array | Array of column names to convert. Set to null or [] for all. |
Returns:
- Type
- df
(static) filter(func, dataframe) → {df}
Filter dataframe rows by using a filtering function.
Accepts a test function that determines which rows of the supplied dataframe are returned.
Example
const df = [{"label": "A", "value": 2}, {"label": "B", "value": 10}, {"label": "C", "value": 30}]
Z.filter(r => r.value >= 10, df)
// [{"label": "B", "value": 10}, {"label": "C", "value": 30}]
Parameters:
Name | Type | Description |
---|---|---|
func |
function | A filtering function |
dataframe |
df | Zebras dataframe to filter |
Returns:
Zebras dataframe
- Type
- df
(static) gbApply(func, groupByObj) → {df}
- Source:
Maps groups using the provided function.
Example
const df = [{"Day": "Monday", "value": 10}, {"Day": "Tuesday", "value": 5}, {"Day": "Monday", "value": 7}]
const grouped = Z.groupBy(x => x.Day, df)
Z.gbApply((group, index) => ({Day: index, value: Z.sum(Z.getCol("value", group))}), grouped)
// [{ Day: "Monday", value: 17 }, { Day: "Tuesday", value: 5 }]
Parameters:
Name | Type | Description |
---|---|---|
func |
function | A mapper function |
groupByObj |
Object | Object grouped by a column |
Returns:
Zebras dataframe
- Type
- df
(static) gbCount(col, groupByObj) → {df}
- Source:
- See:
-
- Z.groupBy, Z.gbMin, Z.gbMax, Z.gbStd, Z.gbSum, Z.gbMean, Z.gbDescribe
Calculate count for grouped objects.
Use it on groupBy objects - the output of Z.groupBy() - to analyze groups.
Example
const df = [{"label": "A", "value": 7}, {"label": "A", "value": 3}, {"label": "B", "value": 2}, {"label": "B", "value": 5}, {"label": "C", "value": 75}]
Z.gbCount("value", Z.groupBy(d => d.label, df))
// [{"count": 2, "group": "A"}, {"count": 2, "group": "B"}, {"count": 1, "group": "C"}]
Parameters:
Name | Type | Description |
---|---|---|
col |
String | Column within the groups to be analyzed |
groupByObj |
Object | Object grouped by a column |
Returns:
Dataframe with the calculated statistics
- Type
- df
(static) gbDescribe(col, groupByObj) → {df}
- Source:
- See:
-
- Z.groupBy, Z.gbStd, Z.gbMin, Z.gbCount, Z.gbSum, Z.gbMean, Z.max
Describe grouped objects.
Use it on groupBy objects - the output of Z.groupBy() - to analyze groups.
Example
const df = [{"label": "A", "value": 7}, {"label": "A", "value": 3}, {"label": "B", "value": 2}, {"label": "B", "value": 5}, {"label": "C", "value": 75}]
Z.gbDescribe("value", Z.groupBy(d => d.label, df))
// [
// { count: 2, group: "A", max: 7, mean: 5, min: 3, std: 2.8284271247461903, sum: 10 },
// { count: 2, group: "B", max: 5, mean: 3.5, min: 2, std: 2.1213203435596424, sum: 7 },
// { count: 1, group: "C", max: 75, mean: 75, min: 75, std: NaN, sum: 75 },
// ]
Parameters:
Name | Type | Description |
---|---|---|
col |
String | Column within the groups to be analyzed |
groupByObj |
Object | Object grouped by a column |
Returns:
Dataframe with the calculated statistics
- Type
- df
(static) gbMax(col, groupByObj) → {df}
- Source:
- See:
-
- Z.groupBy, Z.gbStd, Z.gbMin, Z.gbCount, Z.gbSum, Z.gbMean, Z.gbDescribe
Calculate max for grouped objects.
Use it on groupBy objects - the output of Z.groupBy() - to analyze groups.
Example
const df = [{"label": "A", "value": 7}, {"label": "A", "value": 3}, {"label": "B", "value": 2}, {"label": "B", "value": 5}, {"label": "C", "value": 75}]
Z.gbMax("value", Z.groupBy(d => d.label, df))
// [{"group": "A", "max": 7}, {"group": "B", "max": 5}, {"group": "C", "max": 75}]
Parameters:
Name | Type | Description |
---|---|---|
col |
String | Column within the groups to be analyzed |
groupByObj |
Object | Object grouped by a column |
Returns:
Dataframe with the calculated statistics
- Type
- df
(static) gbMean(col, groupByObj) → {df}
- Source:
- See:
-
- Z.groupBy, Z.gbMin, Z.gbMax, Z.gbCount, Z.gbSum, Z.gbStd, Z.gbDescribe
Calculate mean for grouped objects.
Use it on groupBy objects - the output of Z.groupBy() - to analyze groups.
Example
const df = [{"label": "A", "value": 7}, {"label": "A", "value": 3}, {"label": "B", "value": 2}, {"label": "B", "value": 5}, {"label": "C", "value": 75}]
Z.gbMean("value", Z.groupBy(d => d.label, df))
// [{"group": "A", "mean": 5}, {"group": "B", "mean": 3.5}, {"group": "C", "mean": 75}]
Parameters:
Name | Type | Description |
---|---|---|
col |
String | Column within the groups to be analyzed |
groupByObj |
Object | Object grouped by a column |
Returns:
Dataframe with the calculated statistics
- Type
- df
(static) gbMin(col, groupByObj) → {df}
- Source:
- See:
-
- Z.groupBy, Z.gbStd, Z.gbMax, Z.gbCount, Z.gbSum, Z.gbMean, Z.gbDescribe
Calculate min for grouped objects.
Use it on groupBy objects - the output of Z.groupBy() - to analyze groups.
Example
const df = [{"label": "A", "value": 7}, {"label": "A", "value": 3}, {"label": "B", "value": 2}, {"label": "B", "value": 5}, {"label": "C", "value": 75}]
Z.gbMin("value", Z.groupBy(d => d.label, df))
// [{"group": "A", "min": 3}, {"group": "B", "min": 2}, {"group": "C", "min": 75}]
Parameters:
Name | Type | Description |
---|---|---|
col |
String | Column within the groups to be analyzed |
groupByObj |
Object | Object grouped by a column |
Returns:
Dataframe with the calculated statistics
- Type
- df
(static) gbStd(col, groupByObj) → {df}
- Source:
- See:
-
- Z.groupBy, Z.gbMin, Z.gbMax, Z.gbCount, Z.gbSum, Z.gbMean, Z.gbDescribe
Calculate std for grouped objects.
Use it on groupBy objects - the output of Z.groupBy() - to analyze groups.
Example
const df = [{"label": "A", "value": 7}, {"label": "A", "value": 3}, {"label": "B", "value": 2}, {"label": "B", "value": 5}, {"label": "C", "value": 75}]
Z.gbStd("value", Z.groupBy(d => d.label, df))
// [{"group": "A", "std": 2.8284271247461903}, {"group": "B", "std": 2.1213203435596424}, {"group": "C", "std": NaN}]
Parameters:
Name | Type | Description |
---|---|---|
col |
String | Column within the groups to be analyzed |
groupByObj |
Object | Object grouped by a column |
Returns:
Dataframe with the calculated statistics
- Type
- df
(static) gbSum(col, groupByObj) → {df}
- Source:
- See:
-
- Z.groupBy, Z.gbMin, Z.gbMax, Z.gbCount, Z.gbMean, Z.gbStd, Z.gbDescribe
Calculate sums for grouped objects.
Use it on groupBy objects - the output of Z.groupBy() - to analyze groups.
Example
const df = [{"label": "A", "value": 7}, {"label": "A", "value": 3}, {"label": "B", "value": 2}, {"label": "B", "value": 5}, {"label": "C", "value": 75}]
Z.gbSum("value", Z.groupBy(d => d.label, df))
// [{"group": "A", "sum": 10}, {"group": "B", "sum": 7}, {"group": "C", "sum": 75}]
Parameters:
Name | Type | Description |
---|---|---|
col |
String | Column within the groups to be analyzed |
groupByObj |
Object | Object grouped by a column |
Returns:
Dataframe with the calculated statistics
- Type
- df
(static) getCol(col, dataframe) → {Array}
Extract a series to an array from a dataframe.
Example
const df = [{"label": "A", "value": "2010-12-13"}, {"label": "B", "value": "2010-12-15"}, {"label": "C", "value": "2010-12-17"}]
Z.getCol("value", df)
// ["2010-12-13", "2010-12-15", "2010-12-17"]
Parameters:
Name | Type | Description |
---|---|---|
col |
String | Name of the column to extract |
dataframe |
df | Zebras dataframe |
Returns:
Series array
- Type
- Array
(static) getRange(arr) → {Array}
- Source:
Range of series.
Example
const series = [7, 2, 30, 56, 75]
Z.getRange(series)
// [2, 75]
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | Array of values |
Returns:
Array with min and max
- Type
- Array
(static) groupBy(func, dataframe) → {Object}
- Source:
Create an object grouped by according to the supplied function.
Example
const df = [{"Day": "Monday", "value": 10}, {"Day": "Tuesday", "value": 5}, {"Day": "Monday", "value": 7}]
Z.groupBy(x => x.Day, df)
// {"Monday": [{"Day": "Monday", "value": 10}, {"Day": "Monday", "value": 7}], "Tuesday": [{"Day": "Tuesday", "value": 5}]}
Parameters:
Name | Type | Description |
---|---|---|
func |
function | Function returning string key |
dataframe |
df | Zebras dataframe |
Returns:
- Type
- Object
(static) head(n, dataframe) → {df}
Return dataframe with first n rows of input dataframe.
Example
Z.head(3, df)
// returns a new dataframe with the first 3 lines of `df`
Parameters:
Name | Type | Description |
---|---|---|
n |
Number | Number of rows to select from start of df |
dataframe |
df |
Returns:
Zebras dataframe
- Type
- df
(static) kurt(arr) → {Number}
Kurtosis of a series.
Example
const series = [7, 2, 30, 56, 75]
Z.kurt(series)
// -2.040541067936147
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | Series to calculate kurtosis for |
Returns:
- Type
- Number
(static) max(arr) → {Number}
Max of series.
Example
const series = [7, 2, 30, 56, 75]
Z.max(series)
// 75
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | Array of values |
Returns:
- Type
- Number
(static) mean(arr) → {Number}
Mean of series.
Example
const series = [7, 2, 30, 56, 75]
Z.mean(series)
// 34
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | Series to calculate mean for |
Returns:
- Type
- Number
(static) median(arr) → {Number}
Median of series.
Example
const series = [7, 2, 30, 56, 75]
Z.median(series)
// 30
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | Series to calculate median for |
Returns:
- Type
- Number
(static) merge(dfLeft, dfRight, leftOn, rightOn, leftSuffix, rightSuffix) → {df}
Join two dataframes on a column.
Performs a left join on two dataframes. The 'On' arguments set which column in each df to join on. The 'Suffix' arguments determine what the suffix should be when the two dataframes have overlapping column names besides the one being joined on.
Example
const df1 = [{"label": "A", "value": 7}, {"label": "B", "value": 2}, {"label": "C", "value": 75}]
const df2 = [{"label": "A", "value": "2010-12-13"}, {"label": "B", "value": "2010-12-15"}, {"label": "C", "value": "2010-12-17"}]
Z.merge(df1, df2, "label", "label", "_df1", "_df2")
// [
// { label: "A", value_df1: 7, value_df2: "2010-12-13" },
// { label: "B", value_df1: 2, value_df2: "2010-12-15" },
// { label: "C", value_df1: 75, value_df2: "2010-12-17" },
// ]
Parameters:
Name | Type | Description |
---|---|---|
dfLeft |
df | First dataframe |
dfRight |
df | Second dataframe |
leftOn |
String | Left column to join on |
rightOn |
String | Right column to join on |
leftSuffix |
String | Left suffix for overlapping column names |
rightSuffix |
String | Right suffix for overlapping column names |
Returns:
Joined dataframe
- Type
- df
(static) min(arr) → {Number}
Min of series.
Example
const series = [7, 2, 30, 56, 75]
Z.min(series)
// 2
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | Array of values |
Returns:
- Type
- Number
(static) parseDates(cols, dataframe) → {df}
- Source:
Convert columns to datestamp.
Example
const df = [{"label": "A", "value": "2010-12-13"}, {"label": "B", "value": "2010-12-15"}, {"label": "C", "value": "2010-12-17"}]
Z.parseDates(["value"], df)
// [{"label": "A", "value": 1292198400000}, {"label": "B", "value": 1292371200000}, {"label": "C", "value": 1292544000000}]
Parameters:
Name | Type | Description |
---|---|---|
cols |
Array | Array of column names to convert |
dataframe |
df | Zebras dataframe to parse |
Returns:
Zebras dataframe
- Type
- df
(static) parseNums(columnNames, dataframe) → {df}
- Source:
Convert columns to numerical type (floats).
Example
const df = [{"label": "A", "value": "7"}, {"label": "B", "value": "2"}, {"label": "C", "value": "75"}]
Z.parseNums(["value"], df)
// [{"label": "B", "value": 2}, {"label": "A", "value": 7}, {"label": "C", "value": 75}]
Parameters:
Name | Type | Description |
---|---|---|
columnNames |
Array | Array of column names to convert |
dataframe |
df | Zebras dataframe to parse |
Returns:
Zebras dataframe
- Type
- df
(static) pctChange(arr) → {Array}
- Source:
Percent changes
Returns a new series with the percent changes between the values in order of the input series.
Example
const series = [10, 15, 20, 25, 50, 55]
Z.pctChange(series)
// [NaN, 0.5, 0.33333333333333326, 0.25, 1, 0.10000000000000009]
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | Series to calculate percent changes for |
Returns:
- Type
- Array
(static) pickCols(cols, dataframe) → {df}
- Source:
Select a subset of columns.
Accepts an array with the names of the columns to retain.
Example
const df = [{"label": "A", "value": 7}, {"label": "B", "value": 2}, {"label": "C", "value": 75}]
Z.pickCols(["value"], df)
// [{"value": 7}, {"value": 2}, {"value": 75}]
Parameters:
Name | Type | Description |
---|---|---|
cols |
Array | Array of column names to pick |
dataframe |
df | Zebras dataframe |
Returns:
Zebras dataframe
- Type
- df
(static) pipe(functions, dataframe) → {any}
Pipe functions together by performing left-to-right function composition.
Example
const data = [
{"Date": "1997-01-01", "Value": "12"},
{"Date": "1997-01-02", "Value": "14"},
{"Date": "1997-01-03", "Value": "7"},
{"Date": "1997-01-04", "Value": "112"}
]
Z.pipe([
Z.parseNums(["Value"]), // converts "Value" column to floats
Z.getCol("Value"), // extracts "Value" column to array
Z.mean() // calculates mean of "Value" array
])(data)
// 36.25
Parameters:
Name | Type | Description |
---|---|---|
functions |
Array | Array of functions to compose |
dataframe |
df | Zebras dataframe |
Returns:
Result of the composed functions applied to dataframe
- Type
- any
(static) print(dataframe) → {String}
Prints dataframe.
Returns the entire dataframe as an ASCII table.
If working in a local Node environment, wrap this and other printing
functions in console.log()
to display ASCII tables.
Example
Z.print(df)
// will output an ASCII table like this:
┌────────────┬───────┬───────┬───────┬───────┬───────────┬─────────┐
│ Date │ Open │ High │ Low │ Close │ Adj Close │ Volume │
├────────────┼───────┼───────┼───────┼───────┼───────────┼─────────┤
│ 1950-01-03 │ 16.66 │ 16.66 │ 16.66 │ 16.66 │ 16.66 │ 1260000 │
├────────────┼───────┼───────┼───────┼───────┼───────────┼─────────┤
│ 1950-01-04 │ 16.85 │ 16.85 │ 16.85 │ 16.85 │ 16.85 │ 1890000 │
├────────────┼───────┼───────┼───────┼───────┼───────────┼─────────┤
│ 1950-01-05 │ 16.93 │ 16.93 │ 16.93 │ 16.93 │ 16.93 │ 2550000 │
├────────────┼───────┼───────┼───────┼───────┼───────────┼─────────┤
│ 1950-01-06 │ 16.98 │ 16.98 │ 16.98 │ 16.98 │ 16.98 │ 2010000 │
├────────────┼───────┼───────┼───────┼───────┼───────────┼─────────┤
│ 1950-01-09 │ 17.08 │ 17.08 │ 17.08 │ 17.08 │ 17.08 │ 2520000 │
└────────────┴───────┴───────┴───────┴───────┴───────────┴─────────┘
Parameters:
Name | Type | Description |
---|---|---|
dataframe |
df | to print |
Returns:
Entire dataframe as an ASCII table
- Type
- String
(static) printHead(n, dataframe) → {String}
- Source:
- See:
-
- Z.print, Z.printTail
Print first n rows of dataframe.
Example
Z.printHead(3, df)
// will output an ASCII table like this:
┌────────────┬───────┬───────┬───────┬───────┬───────────┬─────────┐
│ Date │ Open │ High │ Low │ Close │ Adj Close │ Volume │
├────────────┼───────┼───────┼───────┼───────┼───────────┼─────────┤
│ 1950-01-05 │ 16.93 │ 16.93 │ 16.93 │ 16.93 │ 16.93 │ 2550000 │
├────────────┼───────┼───────┼───────┼───────┼───────────┼─────────┤
│ 1950-01-06 │ 16.98 │ 16.98 │ 16.98 │ 16.98 │ 16.98 │ 2010000 │
├────────────┼───────┼───────┼───────┼───────┼───────────┼─────────┤
│ 1950-01-09 │ 17.08 │ 17.08 │ 17.08 │ 17.08 │ 17.08 │ 2520000 │
└────────────┴───────┴───────┴───────┴───────┴───────────┴─────────┘
Parameters:
Name | Type | Description |
---|---|---|
n |
Number | Number of rows to print |
dataframe |
df |
Returns:
First n
rows of dataframe as an ASCII table
- Type
- String
(static) printTail(n, dataframe) → {String}
- Source:
- See:
-
- Z.print, Z.printHead
Print last n rows of dataframe.
Example
Z.printTail(3, df)
// will output an ASCII table like this:
┌────────────┬───────┬───────┬───────┬───────┬───────────┬─────────┐
│ Date │ Open │ High │ Low │ Close │ Adj Close │ Volume │
├────────────┼───────┼───────┼───────┼───────┼───────────┼─────────┤
│ 1950-01-05 │ 16.93 │ 16.93 │ 16.93 │ 16.93 │ 16.93 │ 2550000 │
├────────────┼───────┼───────┼───────┼───────┼───────────┼─────────┤
│ 1950-01-06 │ 16.98 │ 16.98 │ 16.98 │ 16.98 │ 16.98 │ 2010000 │
├────────────┼───────┼───────┼───────┼───────┼───────────┼─────────┤
│ 1950-01-09 │ 17.08 │ 17.08 │ 17.08 │ 17.08 │ 17.08 │ 2520000 │
└────────────┴───────┴───────┴───────┴───────┴───────────┴─────────┘
Parameters:
Name | Type | Description |
---|---|---|
n |
Number | Number of rows to print |
dataframe |
df |
Returns:
Last n
rows of dataframe as an ASCII table
- Type
- String
(static) prod(arr) → {Number}
Product of series.
Example
const series = [7, 2, 30, 56, 75]
Z.prod(series)
// 1764000
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | Array of values |
Returns:
- Type
- Number
(static) qcut(Integer, array) → {Array}
Quantile Cut: For input array X, return each values quantile where Q is the number of quantiles to use. Based on pandas qcut. Uses midpoint interpolation.
Example
const series = [...Array(275).keys()]
Z.valueCounts(Z.quantile(series))
// {"0":55, "1":55, "2":55, "3":55, "4":55, "5":55}
Parameters:
Name | Type | Description |
---|---|---|
Integer |
Number | for the number of quantiles to use |
array |
Array | of values to calculate |
Returns:
- Type
- Array
(static) quantile(quantile, array) → {Number}
- Source:
Quantile of a value in a series of series using midpoint interpolation. see https://numpy.org/doc/stable/reference/generated/numpy.percentile.html
Example
const series = [7, 2, 30, 56, 75, 150]
Z.quantile(.95, series)
// 112.5
Parameters:
Name | Type | Description |
---|---|---|
quantile |
Number | to calculate as represented by a number from 0 to 1 |
array |
Array | of values to calculate percentile from |
Returns:
- Type
- Number
(static) randomSample(n, dataframe) → {df}
- Source:
- See:
-
- Z.slice, Z.tail
Return dataframe with first n rows of input dataframe.
Example
Z.randomSample(3, df)
// returns a new dataframe with the 3 random rows of `df`
Parameters:
Name | Type | Description |
---|---|---|
n |
Number | Number of rows to select from start of df |
dataframe |
df |
Returns:
Zebras dataframe
- Type
- df
(static) readCSV(filepath) → {df}
- Source:
Synchronously reads a CSV file.
Example
Z.readCSV(filepath)
Parameters:
Name | Type | Description |
---|---|---|
filepath |
String | File path for the CSV file to read |
Returns:
Zebras dataframe
- Type
- df
(static) renameCols(mapper, dataframe) → {df}
- Source:
Rename columns.
Example
const df = [{"label": "A", "value": 7}, {"label": "B", "value": 2}, {"label": "C", "value": 75}]
Z.renameCols({"label": "name"}, df)
// [{"name": "A", "value": 7}, {"name": "B", "value": 2}, {"name": "C", "value": 75}]
Parameters:
Name | Type | Description |
---|---|---|
mapper |
Object | Dictionary in the format {"oldColName": "newColName"} |
dataframe |
df | Zebras dataframe |
Returns:
Zebras dataframe
- Type
- df
(static) rolling(func, n, arr) → {Array}
- Source:
Calculate rolling statistics
Calculate statistics over a moving window. Works with Z.min, Z.max, Z.mean, Z.std, Z.sum, Z.prod, or any other function that takes an array as a single argument.
Example
const series = [7, 2, 30, 30, 56, 75]
Z.rolling(Z.mean, 2, series)
// ["NotANumber", 4.5, 16, 30, 43, 65.5]
Parameters:
Name | Type | Description |
---|---|---|
func |
function | Function to caclulate rolling statistics |
n |
Number | Range (?) |
arr |
Array | Series to calculate rolling statistics for |
Returns:
- Type
- Array
(static) skew(arr) → {Number}
Skew of a series.
Example
const series = [7, 2, 30, 56, 75]
Z.skew(series)
// 0.17542841315728933
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | Series to calculate skew for |
Returns:
- Type
- Number
(static) slice(start, end, dataframe) → {df}
Get dataframe rows by index.
Example
const df = [{"label": "A", "value": 7}, {"label": "B", "value": 2}, {"label": "C", "value": 75}]
Z.slice(1, 2, df)
// [{"label": "B", "value": 2}]
Parameters:
Name | Type | Description |
---|---|---|
start |
Number | The start index (inclusive). |
end |
Number | The end index (exclusive). |
dataframe |
df | Zebras dataframe |
Returns:
Zebras dataframe
- Type
- df
(static) sort(func, dataframe) → {df}
Sort dataframe rows using custom sorting function.
Accepts a sorting function that determines the order of rows in the returned dataframe.
Example
const df = [{"label": "A", "value": 7}, {"label": "B", "value": 2}, {"label": "C", "value": 75}]
Z.sort((a, b) => b.value - a.value, df)
// [{ label: "C", value: 75 },{ label: "A", value: 7 },{ label: "B", value: 2 }]
Parameters:
Name | Type | Description |
---|---|---|
func |
function | A sorting function |
dataframe |
df | Zebras dataframe to sort |
Returns:
Zebras dataframe
- Type
- df
(static) sortByCol(col, direction, dataframe) → {df}
- Source:
Sort dataframe rows by a column.
Example
const df = [{"label": "A", "value": 7}, {"label": "B", "value": 2}, {"label": "C", "value": 75}]
Z.sortByCol("value", "asc", df)
// [{"label": "B", "value": 2}, {"label": "A", "value": 7}, {"label": "C", "value": 75}]
Parameters:
Name | Type | Description |
---|---|---|
col |
String | Name of the column to sort by |
direction |
String | Determines direction, pass |
dataframe |
df | Zebras dataframe to sort |
Returns:
Zebras dataframe
- Type
- df
(static) std(arr) → {Number}
Standard deviation of series.
Example
const series = [7, 2, 30, 56, 75]
Z.std(series)
// 31.36080356113344
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | Series to calculate standard deviation for |
Returns:
- Type
- Number
(static) sum(arr) → {Number}
Sum of series.
Example
const series = [7, 2, 30, 56, 75]
Z.sum(series)
// 170
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | Array of values |
Returns:
- Type
- Number
(static) tail(n, dataframe) → {df}
Return a dataframe with the last n rows of input dataframe.
Example
Z.tail(3, df)
// returns a new dataframe with the last 3 lines of `df`
Parameters:
Name | Type | Description |
---|---|---|
n |
Number | Number of rows to select from bottom of df |
dataframe |
df |
Returns:
Zebras dataframe
- Type
- df
(static) toCSV(df, filepath) → {undefined}
Synchronously writes a dataframe to a CSV file.
Example
Z.toCSV(filepath, df)
Parameters:
Name | Type | Description |
---|---|---|
df |
df | Zebras dataframe to write |
filepath |
String | File path for the CSV file to write |
Returns:
- Type
- undefined
(static) unique(arr) → {Array}
Get unique values in a series.
Example
const series = [7, 7, 2, 30, 30, 56, 75]
Z.unique(series)
// [7, 2, 30, 56, 75]
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | Array of values |
Returns:
- Type
- Array
(static) valueCounts(arr) → {Object}
- Source:
Count number of occurences of each value in a series.
Example
const series = [7, 2, 30, 30, 56, 75]
Z.valueCounts(series)
// {"2": 1, "30": 2, "56": 1, "7": 1, "75": 1}
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | Array of values |
Returns:
- Type
- Object