bblocks.import_tools.world_bank =============================== .. py:module:: bblocks.import_tools.world_bank Attributes ---------- .. autoapisummary:: bblocks.import_tools.world_bank.PINK_SHEET_URL Classes ------- .. autoapisummary:: bblocks.import_tools.world_bank.WorldBankData bblocks.import_tools.world_bank.PinkSheet Functions --------- .. autoapisummary:: bblocks.import_tools.world_bank._get_wb_data bblocks.import_tools.world_bank.clean_prices bblocks.import_tools.world_bank.clean_index bblocks.import_tools.world_bank.read_pink_sheet Module Contents --------------- .. py:data:: PINK_SHEET_URL :value: 'https://thedocs.worldbank.org/en/doc/5d903e848db1d1b83e0ec8f744e55570-0350012021/related/CMO-His... .. py:function:: _get_wb_data(indicator: str, db: int, start_year: int | None = None, end_year: int | None = None, most_recent_only: bool = False) -> pandas.DataFrame Get _data for an indicator, using wbgapi .. py:class:: WorldBankData Bases: :py:obj:`bblocks.import_tools.common.ImportData` An object to help download data from the World Bank. In order to use, create an instance of this class. Then, call the load_indicator method to load an indicator. This can be done multiple times. If the _data for an indicator has never been downloaded, it will be downloaded. If it has been downloaded, it will be loaded from disk. If `update_data` is set to True when creating the object, the _data will be updated from the World Bank for each indicator. You can force an update by calling `update` if you want to refresh the _data stored on disk. You can get a dataframe of the _data by calling `get_data`. .. py:attribute:: _indicators :type: dict[str, tuple[pandas.DataFrame, dict]] .. py:method:: load_data(indicator: str | list[str], start_year: int | None = None, end_year: int | None = None, most_recent_only: bool = False, db: int = 2, **kwargs) -> WorldBankData Get an indicator from the World Bank API :param indicator: the code from the World Bank data portal (e.g. "SP.POP.TOTL") :param start_year: The first year to include in the data :param end_year: The last year to include in the data :param most_recent_only: If True, only get the most recent non-empty value for each country :param db: The database to use. By default, use the WDI database (2) :returns: The same object to allow chaining .. py:method:: update_data(reload_data: bool = True) -> bblocks.import_tools.common.ImportData Update the _data saved on disk for the different indicators When called, it will go through each indicator and update the _data saved based on the parameters passed to load_indicator. :returns: The same object to allow chaining .. py:method:: get_data(indicators: str | list = 'all', **kwargs) -> pandas.DataFrame .. py:function:: clean_prices(df: pandas.DataFrame) -> pandas.DataFrame Clean Pink Sheet price _data .. py:function:: clean_index(df: pandas.DataFrame) -> pandas.DataFrame Clean Pink Sheet Index index _data .. py:function:: read_pink_sheet(indicator: str) -> pandas.DataFrame Extracts and cleans _data from the pink sheet excel file :param indicator: the indicator to extract from the pink sheet. Either "prices" or "index" :returns: A clean pandas DataFrame with the _data .. py:class:: PinkSheet Bases: :py:obj:`bblocks.import_tools.common.ImportData` An object to help download _data from World Bank Pink sheets. In order to use, create an instance of this class, specifying the sheet name - 'Monthly Prices', 'Monthly Indices'. Then, call the load_indicator method to load an indicator, optionally specifying in indicator or list of indicators. This can be done multiple times. If the _data has never been downloaded, it will be downloaded. If it has been downloaded, it will be loaded from disk. If `update_data` is set to True when creating the object, the full dataset will be downloaded to disk when `load_indicator` is called for the first time. You can force an update by calling `update` if you want to refresh the data stored on disk. You can get a dataframe of the data by calling `get_data` .. py:method:: load_data(indicator: str = 'prices') -> bblocks.import_tools.common.ImportData Load data for an indicator or list of indicators. Args: indicator: The indicator to load. Choose from 'prices' or 'indices'. Default is 'prices' :returns: The same object to allow chaining .. py:method:: update_data(reload_data: bool = True) -> bblocks.import_tools.common.ImportData Update the _data saved on disk When called it downloads Pink sheet Data from the World Bank and saves it to disk. Optionally specify whether to reload the _data to the object :returns: The same object to allow chaining