pydeflate
Subpackages
Submodules
Functions
|
Deflate amounts to a given currency - base year combination. |
|
|
|
Run to update all underlying data. |
|
Update dac1 data from OECD site and save as feather |
|
Package Contents
- pydeflate.deflate(df: pandas.DataFrame, base_year: int, deflator_source: str = None, deflator_method: str | None = None, exchange_source: str | None = None, exchange_method: str | None = None, source_currency: str = 'USA', target_currency: str = 'USA', id_column: str = 'iso_code', id_type: str = 'ISO3', date_column: str = 'date', source_column: str = 'value', target_column: str = 'value', to_current: bool = False, method: str | None = None, source: str | None = None, iso_column: str | None = None, source_col: str | None = None, target_col: str | None = None) pandas.DataFrame
Deflate amounts to a given currency - base year combination.
Takes a DataFrame containing flows data and returns a DataFrame containing the deflated amounts. It can also convert from constant to current by specifying to_current as ‘True’.
- Parameters:
df – the DataFrame containing the flows column to be deflated. If multiple columns need to be deflated, the function needs to be called multiple times.
base_year – If converting from current to constant, the target base year for the constant figures. If converting from constant, the base year of the data.
deflator_source – {‘oecd_dac’, ‘wb’, ‘imf’} The source of the data used to build the deflators. The value (and completeness) of the price deflators may change based on the source. Additionally, the OECD DAC data is only available for DAC donors.
deflator_method –
{‘gdp’, ‘gdp_linked’, ‘cpi’, ‘pcpi’, ‘pcpie’, None} The method used to calculate the price deflator:
For World Bank (source == ‘wb’), default is “gdp”:
•’gdp’: using GDP deflators.
•’gdp_linked’: a GDP deflator series which has been linked to produce a consistent time series to counteract breaks in series over time due to changes in base years, sources or methodologies.
•’cpi’: using Consumer Price Index data
For IMF (source == ‘imf’), default is “gdp”:
•’pcpi’: Consumer Price Index data
•’pcpie’: end-period Consumer Price Index (e.g. for December each year).
For OECD DAC (source == ‘oecd_dac’), default is “dac_deflator”: •’dac_deflator’: using the OECD DAC deflator
exchange_source – The source of the exchange rates. If None, the exchange rates
used. (default exchange method of the exchange_source will be)
exchange_method – The method used to calculate the exchange rates. If None, the
used.
source_currency – The iso3 code of the source currency. Note that deflators for EU countries are only in Euros from the year in which the Euro was adopted. To produce deflators only in euros, use ‘emu’.
target_currency – The iso3 code of the deflated amounts. It can be the same as the source currency. In cases where they are different, the exchange rate will be applied. To produce deflators only in euros, use ‘emu’.
id_column – The column containing the id codes (iso3 codes, for example) of the data’s
currency.
id_type – The classification type for the id_column. By default, ISO3 but others are possible. Any options used in the Country Converter package are valid. For the OECD DAC classification, use ‘DAC’.
date_column – The column containing the date values. The column can contain years (int) or datetime objects.
source_column – The column containing the data to be deflated.
target_column – Column where the deflated data will be stored. It can be the same as the source column if a copy of the original isn’t needed.
to_current – If True, amounts will be treated as in constant prices and converted to
prices. (current)
iso_column – Provided for backwards compatibility. An alias for id_column
source – Provided for backwards compatibility. An alias for deflator_source
method – Provided for backwards compatibility. An alias for deflator_method
source_col – Provided for backwards compatibility. An alias for source_column
target_col – Provided for backwards compatibility. An alias for target_column
- Returns:
A pandas DataFrame containing the deflated data. Years for which there are no deflators will be returned as null values.
- pydeflate.exchange(df: pandas.DataFrame, source_currency: str, target_currency: str, rates_source: str = 'world_bank', id_column: str = 'iso_code', id_type: str = 'ISO3', value_column: str = 'value', target_column: str = 'value', date_column: str = 'date') pandas.DataFrame
- Parameters:
df (pd.DataFrame) – A Pandas DataFrame, in long format, containing at least a date column, a column with iso-3 codes to identify the source currency, and a value column where the values to be converted are stored.
source_currency (str) – The ISO-3 code of the country which owns the currency in which the data is expressed. “LCU” can be used to indicate that data is in Local Currency Unit. “emu” can be used for the EURO.
target_currency (str) – The ISO-3 code of the country which owns the currency to which the data will be converted. “LCU” can be used to convert from a given currency (like the USD), back to each country’s Local Currency.
rates_source (str, optional) – The source of the exchange rate data. Current options include “wb” for the World Bank and “oecd_dac” for the exchange rates used for ODA statistics. The default is “wb”.
id_column (str, optional) – The name of the column containing the codes or names used to identify countries. The default is “iso_code”.
id_type (str, optional) – The types of codes used to identify countries. Should match options in Country Converter or the DAC codes.The default is “ISO3”.
value_column (str, optional) – The name of the column containing the values to be converted. The default is “value”.
target_column (str, optional) – The name of the column where the converted values will be stored. The default is “value_xe”.
date_column (str, optional) – The name of the column where the date/year is stored. The default is “date”.
- Returns:
df – Returns a dataframe containing the converted data stored in the target column.
- Return type:
pd.DataFrame
- pydeflate.update_all_data() None
Run to update all underlying data.
- pydeflate.update_dac1() None
Update dac1 data from OECD site and save as feather
- pydeflate.set_pydeflate_path(path)