imf_reader.weo.parser ===================== .. py:module:: imf_reader.weo.parser .. autoapi-nested-parse:: Script to parse data from the IMF WEO website. Attributes ---------- .. autoapisummary:: imf_reader.weo.parser.SDMX_FIELDS_TO_MAP imf_reader.weo.parser.SDMX_NUMERIC_COLUMNS Classes ------- .. autoapisummary:: imf_reader.weo.parser.SDMXParser Module Contents --------------- .. py:data:: SDMX_FIELDS_TO_MAP .. py:data:: SDMX_NUMERIC_COLUMNS .. py:class:: SDMXParser Class to parse SDMX data To use this class, call the parse method with the folder containing the SDMX files. .. py:method:: parse_xml(tree: xml.etree.ElementTree.ElementTree) -> pandas.DataFrame :staticmethod: Parse the WEO XML tree and return a DataFrame with the data. :param tree: The XML tree to parse. :returns: A DataFrame with the data. .. py:method:: lookup_schema_element(schema_tree: xml.etree.ElementTree.ElementTree, field_name) -> dict[str, str] :staticmethod: Lookup the elements in the schema and find the label for a given label_name. :param schema_tree: The schema tree to search. :param field_name: The label to search for. :returns: A dictionary with the label codes and label names. .. py:method:: add_label_columns(data_df: pandas.DataFrame, schema_tree: xml.etree.ElementTree.ElementTree) -> pandas.DataFrame :staticmethod: Maps columns with codes to columns with labels and renames the code columns. :param data_df: The DataFrame to add the label columns to. :param schema_tree: The schema tree to search for the labels. :returns: The DataFrame with the label columns and renamed code columns. .. py:method:: check_folder(sdmx_folder: zipfile.ZipFile) -> None :staticmethod: Check that the folder contains the necessary files. This method checks that there is only 1 xml and 1 xsd file in the folder. :param sdmx_folder: The folder to check. .. py:method:: clean_numeric_columns(df: pandas.DataFrame) -> pandas.DataFrame :staticmethod: 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. .. py:method:: parse(sdmx_folder: zipfile.ZipFile) -> pandas.DataFrame :staticmethod: Pipeline to parse the SDMX data files. :param sdmx_folder: The folder containing the SDMX data files. :returns: A DataFrame with the WEO data.