bw2io.importers.excel#

Attributes#

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.

Module Contents#

class bw2io.importers.excel.CSVImporter(filepath, sheet_name=None)[source]#

Bases: ExcelImporter

Generic CSV importer

Initialize the ImportBase object.

Parameters:
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Raises:

NotImplemented : – This class should be subclassed.

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

Bases: bw2io.importers.base_lci.LCIImporter

Generic Excel importer.

Excel spreadsheet should follow the following format. Note that this is an illustrative example, all sections (e.g., parameters) and fields (e.g., exchange columns) are not required.

Database

<name of database>

<database field name>

<database field value>

Project parameters

name

amount

<other parameter field name>

<value>

<value>

<parameter field value>

Database parameters

name

amount

<other parameter field name>

<parameter field value>

<parameter field value>

<parameter field value>

Activity

<name of activity>

<activity field name>

<activity field value>

Parameters

<parameter group>

name

amount

<other parameter field name>

<parameter field value>

<parameter field value>

<parameter field value>

Exchanges

name

amount

<other exchange field name>

<exchange field value>

<exchange field value>

<exchange field value>

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

Blank lines are allowed anywhere, they won’t have any effect. The end of the file is determined in the Excel file based on the content.

The very first cell of the worksheet must not be empty (A1), otherwise the worksheet won’t be imported.

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.

Initialize the ImportBase object.

Parameters:
  • *args – Variable length argument list.

  • **kwargs – Arbitrary keyword arguments.

Raises:

NotImplemented : – This class should be subclassed.

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.

extractor[source]#
format = 'Excel'[source]#
strategies[source]#
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]#