SHARE
TWEET

Untitled

a guest Jul 20th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- coding: utf-8 -*-
  2. """
  3. API Ministerio de Hacienda
  4.  
  5. Autor: Lionel Modi
  6. """
  7. from datetime import datetime as _dt
  8. import requests as _req
  9. import pandas as _pd
  10.  
  11.  
  12. def get_data(ids, **params):
  13.     """
  14.     Baja series del API del Ministerio de Hacienda
  15.  
  16.     Parámetros:
  17.         ids    : list con ids a solicitar
  18.         params : Parámetros para configurar el API
  19.  
  20.     Resultado:
  21.         pandas.DataFrame o pandas.Series
  22.  
  23.     Uso:
  24.         >>> get_data(['168.1_T_CAMBIOR_D_0_0_26'], start_date='2018-07')
  25.     """
  26.     params['ids'] = ",".join(ids)
  27.     params['format'] = 'json'
  28.     params['metadata'] = 'full'
  29.     raw_data = _req.get(r'https://apis.datos.gob.ar/series/api/series',
  30.                             params=params).json()
  31.  
  32.     cols = [r['field']['title'] for r in raw_data['meta'][1:]]
  33.     dts, data = map(list, zip(*[(_dt.strptime(f, "%Y-%m-%d"), d) for
  34.                                 f, *d in raw_data['data']]))
  35.  
  36.     output = _pd.DataFrame.from_records(data=data, index=dts, columns=cols)
  37.  
  38.     return output.squeeze()
  39.  
  40.  
  41. if __name__ == '__main__':
  42.     # Ejemplo 'Tipo de Cambio BNA Vendedor'
  43.     TC = get_data(['168.1_T_CAMBIOR_D_0_0_26'], start_date='2018-01',
  44.                   limit=1000)
  45.  
  46.     # Ejemplo 'IPC Nivel General. Base abr 2016. Mensual'
  47.     INF = get_data(['101.1_I2NG_2016_M_22:percent_change_a_year_ago'])
  48.  
  49.     # Ejemplo 'Reservas Intenacionales BCRA'
  50.     RES = get_data(['92.1_RID_0_0_32'], start_date='2015-01')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top