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

bw2io.importers.excel#

Module Contents#

Classes#

CSVImporter

Generic CSV importer

ExcelImporter

Generic Excel importer.

Functions#

valid_first_cell(sheet, data)

Return boolean if first cell in worksheet is not skip.

Attributes#

is_empty_line

remove_empty

class bw2io.importers.excel.CSVImporter(filepath)[source]#

Bases: ExcelImporter

Inheritance diagram of bw2io.importers.excel.CSVImporter

Generic CSV importer

extractor[source]#
format = 'CSV'[source]#
class bw2io.importers.excel.ExcelImporter(filepath)[source]#

Bases: bw2io.importers.base_lci.LCIImporter

Inheritance diagram of bw2io.importers.excel.ExcelImporter

Generic Excel importer.

Excel spreadsheet should follow the following format:

::

Project parameters <variable>, <formula>, <amount>, metadata

Database, <name of database> <database field name>, <database field value>

Parameters <variable>, <formula>, <amount>, metadata

Activity, <name of activity> <database field name>, <database field value> Exchanges <field name>, <field name>, <field name> <value>, <value>, <value> <value>, <value>, <value>

Neither project parameters, parameters, nor exchanges for each activity are required.

An activity is marked as finished with a blank line.

In general, data is imported without modification. However, the following transformations are applied:

  • Numbers are translated from text into actual numbers.

  • Tuples, separated in the cell by the :: string, are reconstructed.

  • True and False are transformed to boolean values.

  • Fields with the value (Unknown) are dropped.

extractor[source]#
format = 'Excel'[source]#
get_activity(sn, ws)[source]#
get_database(data)[source]#
get_database_parameters(data)[source]#
get_labelled_section(sn, ws, index=0, transform=True)[source]#

Turn a list of rows into a list of dictionaries.

The first line of ws is the column labels. All subsequent rows are the data values. Missing columns are dropped.

transform is a boolean: perform CSV transformation functions like csv_restore_tuples.

get_metadata_section(sn, ws, index=0, transform=True)[source]#
get_project_parameters(data)[source]#

Extract project parameters (variables and formulas).

Project parameters are a section that starts with a line with the string “project parameters” (case-insensitive) in the first cell, and ends with a blank line. There can be multiple project parameter sections.

process_activities(data)[source]#

Take list of (sheet names, raw data) and process it.

write_activity_parameters(data=None, delete_existing=True)[source]#
write_database(**kwargs)[source]#

Same as base write_database method, but activate_parameters is True by default.

write_database_parameters(activate_parameters=True, delete_existing=True)[source]#

Same as base write_database_parameters method, but activate_parameters is True by default.

bw2io.importers.excel.valid_first_cell(sheet, data)[source]#

Return boolean if first cell in worksheet is not skip.

bw2io.importers.excel.is_empty_line[source]#
bw2io.importers.excel.remove_empty[source]#