API reference
Top-level functions
Functions available directly on the pd namespace (the default export), mirroring pandas top-level functions.
| Name | Summary |
|---|---|
pd.concat | Concatenate pandas objects along a particular axis. |
pd.merge | Merge DataFrame or named Series objects with a database-style join. |
pd.date_range | Return a fixed frequency DatetimeIndex. |
pd.to_datetime | Convert argument to datetime. |
pd.read_csv | Read a comma-separated values (CSV) file into a DataFrame. |
pd.isna | Detect missing values. Returns boolean Series/DataFrame/scalar. |
pd.notna | Detect non-missing values. Inverse of isna. |
pd.cut | Bin values into discrete intervals. |
pd.qcut | Quantile-based discretization function. |
pd.get_dummies | Convert categorical variable into dummy/indicator variables. |
pd.crosstab | Compute a cross-tabulation of two (or more) factors. |
pd.eval | Evaluate an expression string. With a DataFrame, evaluates column expressions. W |
pd.infer_freq | Infer the most likely frequency of a DatetimeIndex. |
pd.wide_to_long | Wide panel to long format. Less flexible but more user-friendly than melt. |
pd.json_normalize | Normalize semi-structured JSON data into a flat table. |
pd.concat
#pd.concat(objs, options?)
Concatenate pandas objects along a particular axis.
Returns
DataFrame | Series
Example
import pd from 'pandas-ts';
const a = new pd.DataFrame({ x: [1,2] });
const b = new pd.DataFrame({ x: [3,4] });
pd.concat([a, b]).shape; // => [4, 1]pd.merge
#pd.merge(left, right, options?)
Merge DataFrame or named Series objects with a database-style join.
Returns
DataFrame
Example
const left = new pd.DataFrame({ id: [1,2], val: ['a','b'] });
const right = new pd.DataFrame({ id: [1,2], score: [10,20] });
pd.merge(left, right, { on: 'id' }).shape; // => [2, 3]pd.date_range
#pd.date_range(start, options)
Return a fixed frequency DatetimeIndex.
Returns
DatetimeIndex
Example
pd.date_range('2024-01-01', { periods: 5, freq: 'D' }).length; // => 5pd.to_datetime
#pd.to_datetime(arg, options?)
Convert argument to datetime.
Returns
Timestamp | DatetimeIndex
Example
pd.to_datetime('2024-01-15').year; // => 2024pd.read_csv
#pd.read_csv(path, options?)
Read a comma-separated values (CSV) file into a DataFrame.
Returns
DataFrame
Example
// Node.js only
const df = pd.read_csv('data.csv');
df.columns; // column names from the header rowpd.isna
#pd.isna(obj)
Detect missing values. Returns boolean Series/DataFrame/scalar.
Returns
boolean | Series | DataFrame
Example
import { isna } from 'pandas-ts';
isna(null); // => true
isna(NaN); // => true
isna(0); // => falsepd.notna
#pd.notna(obj)
Detect non-missing values. Inverse of isna.
Returns
boolean | Series | DataFrame
Example
import { notna } from 'pandas-ts';
notna(1); // => true
notna(NaN); // => falsepd.cut
#pd.cut(x, bins, options?)
Bin values into discrete intervals.
Returns
Series
Example
import { cut } from 'pandas-ts';
cut(new pd.Series([1,2,3,4,5]), 2).dtype.name; // => 'category'pd.qcut
#pd.qcut(x, q, options?)
Quantile-based discretization function.
Returns
Series
Example
import { qcut } from 'pandas-ts';
qcut(new pd.Series([1,2,3,4,5,6,7,8,9,10]), 4).nunique(); // => 4pd.get_dummies
#pd.get_dummies(data, options?)
Convert categorical variable into dummy/indicator variables.
Returns
DataFrame
Example
pd.get_dummies(new pd.Series(['a','b','a'])).shape; // => [3, 2]pd.crosstab
#pd.crosstab(index, columns, options?)
Compute a cross-tabulation of two (or more) factors.
Returns
DataFrame
Example
const idx = new pd.Series(['a','a','b','b']);
const col = new pd.Series([1,2,1,2]);
pd.crosstab(idx, col).shape; // => [2, 2]pd.eval
#pd.eval(expr, df?)
Evaluate an expression string. With a DataFrame, evaluates column expressions. Without one, evaluates scalar math.
Returns
Series | number
Example
import { pdEval } from 'pandas-ts';
pdEval('2 + 3'); // => 5
pdEval('a + b', new pd.DataFrame({ a: [1,2], b: [3,4] })).to_list(); // => [4, 6]pd.infer_freq
#pd.infer_freq(dates)
Infer the most likely frequency of a DatetimeIndex.
Returns
string | null
Example
import { infer_freq } from 'pandas-ts';
infer_freq(['2024-01-01','2024-01-02','2024-01-03']); // => 'D'
infer_freq(['2024-01-01','2024-02-01','2024-03-01']); // => 'MS'pd.wide_to_long
#pd.wide_to_long(df, stubnames, i, j, options?)
Wide panel to long format. Less flexible but more user-friendly than melt.
Returns
DataFrame
Example
const df = new pd.DataFrame({
id: [1, 2],
sales_2023: [100, 200],
sales_2024: [110, 220],
});
pd.wide_to_long(df, ['sales'], 'id', 'year').shape; // => [4, 2]pd.json_normalize
#pd.json_normalize(data, options?)
Normalize semi-structured JSON data into a flat table.
Returns
DataFrame
Example
pd.json_normalize([{ a: 1, b: { c: 2 } }, { a: 3, b: { c: 4 } }]).columns;
// => ['a', 'b.c']