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.).
| Name | Summary |
|---|---|
read_csv | Read a CSV file into a DataFrame. Supports header, sep, index_col, usecols, dtyp |
to_csv | Write DataFrame to CSV. If path is omitted, returns a string. |
read_json | Convert a JSON string or file to a DataFrame. |
to_json | Convert the object to a JSON string. If path is omitted, returns a string. |
read_excel | Read an Excel file into a DataFrame (powered by xlsx). Supports sheet_name, head |
to_excel | Write DataFrame to an Excel file. |
read_parquet | Read a Parquet file into a DataFrame. Stub — throws unless a compatible Parq |
read_sql | Read SQL query or database table into a DataFrame. |
read_feather | Load a feather-format object from the file path. |
to_feather | Write 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
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
const csv = df.to_csv(); // returns string
df.to_csv('output.csv'); // writes fileread_json
#read_json(path, options?)
Convert a JSON string or file to a DataFrame.
Returns
DataFrame
Example
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
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
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
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
// 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
const df = read_sql('SELECT * FROM users', db);
df.shape; // rows x columnsread_feather
#read_feather(path)
Load a feather-format object from the file path.
Returns
DataFrame
Example
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
df.to_feather('output.feather');