REGISTER NOW: DdS Autumn School! 🇨🇭 Grosshöchstetten (Switzerland) 🗓️ 6.-11. October 2024

bw2io.export.csv#

Module Contents#

Classes#

CSVFormatter

Functions#

reformat(value)

write_lci_csv(database_name[, objs, sections, dirpath])

Export database database_name to a CSV file.

Attributes#

EXCHANGE_COLUMNS

MAPPING

PARAMETER_COLUMNS

class bw2io.export.csv.CSVFormatter(database_name, objs=None)[source]#

Bases: object

exchange_as_dict(exc)[source]#
get_activity(act)[source]#
get_activity_metadata(act)[source]#
get_activity_parameters(act)[source]#
get_database_metadata()[source]#
get_database_parameters()[source]#
get_exchanges(act)[source]#
get_formatted_data(sections=None)[source]#
get_project_parameters()[source]#
get_unformatted_data()[source]#

Return all database data as a nested dictionary:

Returns#

dict

A nested python dictionary with the following structure:

{
‘database’: {

‘name’: name, ‘metadata’: [(key, value)], ‘parameters’: {

‘columns’: [column names], ‘data’: [[column values for each row]]

}, ‘project parameters’: {

‘columns’: [column names], ‘data’: [[column values for each row]]

}

}, ‘activities’: [{

‘name’: name, ‘metadata’: [(key, value)], ‘parameters’: {

‘columns’: [column names], ‘group’: ‘group name’, ‘data’: [[column values for each row]]

}, ‘exchanges’: {

‘columns’: [column names], ‘data’: [[column values for each row]]

}

}]

}

order_dicts(data, kind='exchange')[source]#
bw2io.export.csv.reformat(value)[source]#
bw2io.export.csv.write_lci_csv(database_name, objs=None, sections=None, dirpath=None)[source]#

Export database database_name to a CSV file.

Notes#

Not all data can be exported. The following constraints apply:

  • Nested data, e.g. {‘foo’: {‘bar’: ‘baz’}} are excluded.

  • CSV is not a great format for nested data. However, tuples are exported, and the characters :: are used to join elements of the tuple.

  • The only well-supported data types are strings, numbers, and booleans.

Default directory is projects.output_dir, set dirpath to have save the file somewhere else.

Parameters#

database_namestr

The name of the database to export.

objslist, optional

A list of objects to export. If not provided, all objects in the database will be exported.

sectionslist, optional

A list of sections to export. If not provided, all sections will be exported.

dirpathstr, optional

The directory to save the file to. If not provided, the default directory is projects.output_dir.

Returns#

str

The filepath of the exported file.

bw2io.export.csv.EXCHANGE_COLUMNS = ['name', 'amount', 'database', 'location', 'unit', 'categories', 'type', 'formula', 'uncertainty...[source]#
bw2io.export.csv.MAPPING[source]#
bw2io.export.csv.PARAMETER_COLUMNS = ['name', 'amount', 'formula', 'uncertainty type', 'loc', 'scale', 'shape', 'minimum', 'maximum'][source]#