bw2io.export.csv#

Attributes#

Classes#

Functions#

reformat(value)

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

Export database database_name to a CSV file.

Module Contents#

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:

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]]

}

}]

}

Return type:

dict

order_dicts(data, kind='exchange')[source]#
db[source]#
objs[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_name (str) – The name of the database to export.

  • objs (list, optional) – A list of objects to export. If not provided, all objects in the database will be exported.

  • sections (list, optional) – A list of sections to export. If not provided, all sections will be exported.

  • dirpath (str, optional) – The directory to save the file to. If not provided, the default directory is projects.output_dir.

Returns:

The filepath of the exported file.

Return type:

str

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]#