pydeflate.tools.exchange
Attributes
Functions
|
Check whether provided parameters are valid |
|
|
Module Contents
- pydeflate.tools.exchange._exchange_source
- pydeflate.tools.exchange._check_key_errors(rates_source: str, columns: str | list | pandas.Index, value_column: str, date_column: str) None
Check whether provided parameters are valid
- pydeflate.tools.exchange.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