Input/output

DataFrames and xlsx/csv files

A pandas.DataFrame or a path to an xlsx or csv with data in the required structure (i.e., index/columns) can be imported directly by initializing an IamDataFrame - see this tutorial for more information.

Exporting to these formats is implemented via the following functions:

IamDataFrame.as_pandas(with_metadata=False)[source]

Return object as a pandas.DataFrame

Parameters
with_metadatabool or dict, default False

if True, join data with all meta columns; if a dict, discover meaningful meta columns from values (in key-value)

IamDataFrame.to_excel(excel_writer, sheet_name='data', iamc_index=False, include_meta=True, **kwargs)[source]

Write object to an Excel spreadsheet

Parameters
excel_writer: str, path object or ExcelWriter object

any valid string path, pathlib.Path or pandas.ExcelWriter

sheet_name: string

name of sheet which will contain timeseries() data

iamc_index: bool, default False

if True, use [‘model’, ‘scenario’, ‘region’, ‘variable’, ‘unit’]; else, use all ‘data’ columns

include_meta: boolean or string

if True, write ‘meta’ to an Excel sheet name ‘meta’ (default); if this is a string, use it as sheet name

IamDataFrame.to_csv(path, iamc_index=False, **kwargs)[source]

Write timeseries data of this object to a csv file

Parameters
path: str r path object

file path or pathlib.Path

iamc_index: bool, default False

if True, use [‘model’, ‘scenario’, ‘region’, ‘variable’, ‘unit’]; else, use all ‘data’ columns

The frictionless Data Package

The pyam package supports reading and writing to the frictionless Data Package.

pyam.read_datapackage(path, data='data', meta='meta')[source]

Read timeseries data and meta-indicators from frictionless Data Package

Parameters
pathstring or path object

any valid string path or pathlib.Path,
passed to datapackage.Package() (read the docs)

datastr, default ‘data’

resource containing timeseries data in IAMC-compatible format

metastr, default ‘meta’

(optional) resource containing a table of categorization and quantitative indicators

IamDataFrame.to_datapackage(path)[source]

Write object to a frictionless Data Package

More information: https://frictionlessdata.io

Returns the saved datapackage.Package (read the docs). When adding metadata (descriptors), please follow the template defined by https://github.com/OpenEnergyPlatform/metadata

Parameters
path: string or path object

any valid string path or pathlib.Path