imf_reader.weo.parser
Script to parse data from the IMF WEO website.
Attributes
Classes
Class to parse SDMX data |
Module Contents
- imf_reader.weo.parser.SDMX_FIELDS_TO_MAP
- imf_reader.weo.parser.SDMX_NUMERIC_COLUMNS
- class imf_reader.weo.parser.SDMXParser
Class to parse SDMX data To use this class, call the parse method with the folder containing the SDMX files.
- static parse_xml(tree: xml.etree.ElementTree.ElementTree) pandas.DataFrame
Parse the WEO XML tree and return a DataFrame with the data.
- Parameters:
tree – The XML tree to parse.
- Returns:
A DataFrame with the data.
- static lookup_schema_element(schema_tree: xml.etree.ElementTree.ElementTree, field_name) dict[str, str]
Lookup the elements in the schema and find the label for a given label_name.
- Parameters:
schema_tree – The schema tree to search.
field_name – The label to search for.
- Returns:
A dictionary with the label codes and label names.
- static add_label_columns(data_df: pandas.DataFrame, schema_tree: xml.etree.ElementTree.ElementTree) pandas.DataFrame
Maps columns with codes to columns with labels and renames the code columns.
- Parameters:
data_df – The DataFrame to add the label columns to.
schema_tree – The schema tree to search for the labels.
- Returns:
The DataFrame with the label columns and renamed code columns.
- static check_folder(sdmx_folder: zipfile.ZipFile) None
Check that the folder contains the necessary files.
This method checks that there is only 1 xml and 1 xsd file in the folder.
- Parameters:
sdmx_folder – The folder to check.
- static clean_numeric_columns(df: pandas.DataFrame) pandas.DataFrame
Cleans the numeric columns Replaces non numeric values with null values and converts the columns to numeric and the correct type.
- Returns:
The DataFrame with the numeric columns cleaned.
- static parse(sdmx_folder: zipfile.ZipFile) pandas.DataFrame
Pipeline to parse the SDMX data files.
- Parameters:
sdmx_folder – The folder containing the SDMX data files.
- Returns:
A DataFrame with the WEO data.