py_wlc.data package¶
Submodules¶
py_wlc.data.webtag_data module¶
Exposes the parsed WebTAG data as py_wlc objects.
-
class
py_wlc.data.webtag_data.WebTagData(base_year, released, version, source, **data)[source]¶ Bases:
objectHolds the data extracted from WebTAG.
py_wlc.data.webtag_parser module¶
WebTAG Parser - functionality for extracting from the Data Book.
This class parses the databook to a more convenient JSON format for
use by WebTagData.
-
class
py_wlc.data.webtag_parser.WebTagParser(filename)[source]¶ Bases:
objectClass to handle access to a WebTAG Databook Excel file.
The class is designed to operate as a context manager if needed.
Where possible, the workbook is opened in
on_demandmode, to avoid loading all worksheets at once.extract_data()will load and unload the appropriate worksheets as required.Parameters: filename ( str) – The WebTAG Databook file to open.-
book¶ xlrd.WorkbookThe Excel workbook.
-
date¶ datetime.datetimeThe release date of the databook.
-
filename¶ strThe name of the file to open.
-
version¶ strThe version of the databook.
-
BASE= ('User Parameters', 0, 11, 'Price year')¶ Where to find the base year.
-
CHECK= ('Cover', 2, 0, 'WebTAG Databook')¶ Defines the check for a valid WebTAG workbook.
-
DATE= ('Audit', 0, 2)¶ Where to locate the workbook date.
-
LOCATIONS= {'rail_electricity_price': ('A1.3.7', 27, 1, 7), 'rail_fuel_duty': ('A1.3.7', 27, 1, 10), 'discount_rate': ('A1.1.1', 24, 1, 3), 'rail_diesel_price': ('A1.3.7', 27, 1, 5), 'gdp_growth': ('Annual Parameters', 30, 1, 5)}¶ Locations of defined data series for extraction.
-
VERSION= ('Cover', 3, 0)¶ Where to locate the workbook version.
-
extract_all(verbose=False)[source]¶ Extract all data from
LOCATIONSand useful metadata.Parameters: verbose ( bool, optional) – Whether to report progress. Implemented primarily forcli()usage. Defaults toFalse.Returns: The data extracted from the book.Return type: dict
-
extract_data(sheet_name, start_row, key_col, value_col)[source]¶ Extract data from the specified worksheet.
Assumes that cell
A3contains the worksheet title and that cellA4contains the table name.Parameters: - sheet_name (
str) – The name of the worksheet. - start_row (
int) – The first row to extract data from. - key_col (
int) – The column to extract keys from. - value_col (
int) – The column to extract values from.
Returns: The extracted data
Return type: dict
- sheet_name (
-
-
py_wlc.data.webtag_parser.cli(args)[source]¶ Provide a CLI for the
WebTagParser.Will either output to a specified file (with optional verbose reporting) or dump the JSON data to
stdout.Parameters: args ( argparse.Namespace) – The parsed command line arguments.Raises: ValueError– If-vis supplied without-o.
Module contents¶
py_wlc.data provides external data handling functionality.
Various sources of external data may be required for carrying out economic appraisals; this module provides convenience functions and classes for handling that data.