-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.py
55 lines (44 loc) · 2.47 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pandas as pd
from fredapi import Fred
from bcra_api import BcraApi
def main():
# get an api key from https://estadisticasbcra.com/api/registracion
API_KEY = ''
api_bcra = BcraApi(API_KEY)
df = api_bcra.get_series('milestones')
all_metrics = ['milestones', 'base', 'base_usd', 'base_usd_of', 'reservas',
'base_div_res', 'usd', 'usd_of', 'usd_of_minorista',
'var_usd_vs_usd_of', 'circulacion_monetaria', 'billetes_y_monedas',
'efectivo_en_ent_fin', 'depositos_cuenta_ent_fin', 'depositos',
'cuentas_corrientes', 'cajas_ahorro', 'plazo_fijo', 'tasa_depositos_30_dias',
'prestamos', 'tasa_prestamos_personales', 'tasa_adelantos_cuenta_corriente',
'porc_prestamos_vs_depositos', 'lebac', 'leliq', 'lebac_usd', 'leliq_usd',
'leliq_usd_of', 'tasa_leliq', 'm2_privado_variacion_mensual', 'cer', 'uva',
'uvi', 'tasa_badlar', 'tasa_baibar', 'tasa_tm20', 'tasa_pase_activas_1_dia',
'tasa_pase_pasivas_1_dia', 'inflacion_mensual_oficial', 'inflacion_interanual_oficial',
'var_base_monetaria_interanual', 'var_usd_interanual', 'var_usd_oficial_interanual',
'var_merval_interanual', 'var_usd_anual', 'var_usd_of_anual', 'var_merval_anual',
'merval', 'merval_usd']
merged_df = api_bcra.get_series(all_metrics[0])
for e in all_metrics[1:]:
df_serie = api_bcra.get_series(e)
merged_df = pd.merge(merged_df, df_serie, how='outer' ,on='Date')
return merged_df
if __name__ == "__main__":
df_bcra = main()
df_bcra['Date'] = df_bcra['Date'].astype(str)
df_bcra['Date'] = pd.to_datetime(df_bcra['Date'], format='%Y/%m/%d')
# fredapi get an api key from https://fred.stlouisfed.org/docs/api/fred/#API
fred = Fred(api_key='')
metric = 'DFF'
data = fred.get_series(metric)
df_fed = pd.DataFrame(data)
df_fed.reset_index(inplace=True)
cols = df_fed.columns
df_fed.rename(columns={cols[0]: 'Date', cols[1]: metric}, inplace=True)
df_fed['Date'] = df_fed['Date'].astype(str)
df_fed['Date'] = pd.to_datetime(df_fed['Date'], format='%Y/%m/%d')
df_fed.sort_values('Date', ascending=False, inplace=True)
merged_df = pd.merge(df_bcra, df_fed, how='outer' ,on='Date')
merged_df.sort_values('Date', ascending=False, inplace=True)
merged_df.to_csv('data_bcra.csv')