bw2io.export.csv#
Attributes#
Classes#
Functions#
|
|
|
Export database database_name to a CSV file. |
Module Contents#
- class bw2io.export.csv.CSVFormatter(database_name, objs=None)[source]#
Bases:
object
- 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
- 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
, setdirpath
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