pandas-tspandas-ts
npm

API reference

IO

Functions for reading data into DataFrames and writing DataFrames to files. All read/write functions are available at the top level (pd.read_csv, pd.to_csv, etc.).

NameSummary
read_csvRead a CSV file into a DataFrame. Supports header, sep, index_col, usecols, dtyp
to_csvWrite DataFrame to CSV. If path is omitted, returns a string.
read_jsonConvert a JSON string or file to a DataFrame.
to_jsonConvert the object to a JSON string. If path is omitted, returns a string.
read_excelRead an Excel file into a DataFrame (powered by xlsx). Supports sheet_name, head
to_excelWrite DataFrame to an Excel file.
read_parquetRead a Parquet file into a DataFrame. Stub — throws unless a compatible Parq
read_sqlRead SQL query or database table into a DataFrame.
read_featherLoad a feather-format object from the file path.
to_featherWrite out the binary feather-format representation of the DataFrame.

read_csv

#
read_csv(path, options?)

Read a CSV file into a DataFrame. Supports header, sep, index_col, usecols, dtype, na_values, skiprows, nrows, encoding, and more.

Parameters

pathstring
Path to the CSV file.
options?{ sep?, header?, index_col?, usecols?, dtype?, na_values?, skiprows?, nrows? }
Parse options.

Returns

DataFrame

Example

TypeScript
import { read_csv } from 'pandas-ts';
const df = read_csv('sales.csv');
df.head()

to_csv

#
df.to_csv(path?, options?)

Write DataFrame to CSV. If path is omitted, returns a string.

Returns

string | void

Example

TypeScript
const csv = df.to_csv();    // returns string
df.to_csv('output.csv');    // writes file

read_json

#
read_json(path, options?)

Convert a JSON string or file to a DataFrame.

Returns

DataFrame

Example

TypeScript
read_json('[{"a":1,"b":2},{"a":3,"b":4}]').shape;    // => [2, 2]

to_json

#
df.to_json(path?, options?)

Convert the object to a JSON string. If path is omitted, returns a string.

Returns

string | void

Example

TypeScript
new DataFrame({ a: [1,2] }).to_json();    // => '[{"a":1},{"a":2}]'

read_excel

#
read_excel(path, options?)

Read an Excel file into a DataFrame (powered by xlsx). Supports sheet_name, header, usecols.

Returns

DataFrame

Example

TypeScript
const df = read_excel('data.xlsx', { sheet_name: 'Sheet1' });

to_excel

#
df.to_excel(path, options?)

Write DataFrame to an Excel file.

Returns

void

Example

TypeScript
df.to_excel('output.xlsx', { sheet_name: 'Results' });

read_parquet

#
read_parquet(path)

Read a Parquet file into a DataFrame. Stub — throws unless a compatible Parquet parser is provided.

Returns

DataFrame

Example

TypeScript
// throws: 'Parquet read requires a native parser'

read_sql

#
read_sql(query, connection, options?)

Read SQL query or database table into a DataFrame.

Parameters

querystring
SQL query string or table name.
connectionConnection
Database connection object.

Returns

DataFrame

Example

TypeScript
const df = read_sql('SELECT * FROM users', db);
df.shape;    // rows x columns

read_feather

#
read_feather(path)

Load a feather-format object from the file path.

Returns

DataFrame

Example

TypeScript
const df = read_feather('data.feather');

to_feather

#
df.to_feather(path)

Write out the binary feather-format representation of the DataFrame.

Returns

void

Example

TypeScript
df.to_feather('output.feather');