seriesbr package

Submodules

seriesbr.bcb module

seriesbr.bcb.get_metadata(code)[source]

Get metadata of a BCB’s time series.

Parameters:code (str) – Time series’ code.
Returns:A DataFrame with metadata values.
Return type:pandas.DataFrame

Examples

>>> bcb.get_metadata(20786).head()
                                                                    values
referencias              <P><A href="http://www.bcb.gov.br/estatisticas...
license_title            Licença Aberta para Bases de Dados (ODbL) do O...
maintainer                  Banco Central do Brasil/Departamento Econômico
relationships_as_object                                                 []
vcge                     Política Econômica [http://vocab.e.gov.br/2011...
seriesbr.bcb.get_serie(code, name=None, start=None, end=None, last_n=None)[source]

Auxiliary function to return a single time series from BCB database.

seriesbr.bcb.get_series(*codes, start=None, end=None, last_n=None, **kwargs)[source]

Get multiple series into a DataFrame.

Parameters:
  • codes (dict, str, int) – Dictionary like {“name1”: cod1, “name2”: cod2} or a bunch of code numbers, e.g. cod1, cod2.
  • start (str, optional) – Initial date, month or day first.
  • end (str, optional) – End date, month or day first.
  • last_n (int, optional) – Ignore other arguments and get last n observations.
  • **kwargs – Passed to pandas.concat.
Returns:

A DataFrame with series’ values.

Return type:

pandas.DataFrame

Examples

>>> bcb.get_series({"Spread": 20786}, start="02-2018", end="072018")
            Spread
Date
2018-02-01   33.97
2018-03-01   33.66
2018-04-01   33.03
2018-05-01   30.92
2018-06-01   29.43
2018-07-01   29.39
seriesbr.bcb.search(*search, rows=10, start=1)[source]

Search for a name in the SGS database.

Parameters:
  • rows (int, default 10) – How many results to show.
  • start (int, default 1) – From which row to start showing the results.
  • *search – Arbitrary number of strings to search.
Returns:

A DataFrame with the search results.

Return type:

pandas.DataFrame

Examples

>>> bcb.search("Atividade", "econômica", rows=5, start=2)
  codigo_sgs                                              title periodicidade    unidade_medida
0      27738  Saldo das operações de crédito por atividade e...        mensal  Milhões de reais
1      27742  Saldo das operações de crédito por atividade e...        mensal  Milhões de reais
2      22039  Saldo das operações de crédito por atividade e...        mensal  Milhões de reais
3      22041  Saldo das operações de crédito por atividade e...        mensal  Milhões de reais
4      22027  Saldo das operações de crédito por atividade e...        mensal  Milhões de reais

seriesbr.ibge module

seriesbr.ibge.get_frequency(aggregate)[source]

Auxiliary function to get frequency of a time series from IBGE’s database.

This is needed because in case of a yearly time series, there can’t be months in the url.

seriesbr.ibge.get_metadata(aggregate)[source]

Get metadata of a time series from IBGE’s database.

Parameters:aggregate (str) – Aggregate’s code.
Returns:A DataFrame with metadata values.
Return type:pandas.DataFrame

Examples

>>> ibge.get_metadata(1419)
                                                             values
id                                                             1419
nome              IPCA - Variação mensal, acumulada no ano, acum...
URL                            http://sidra.ibge.gov.br/tabela/1419
pesquisa              Índice Nacional de Preços ao Consumidor Amplo
assunto                                           Índices de preços
periodicidade     {'frequencia': 'mensal', 'inicio': 201201, 'fi...
nivelTerritorial  {'Administrativo': ['N1', 'N6', 'N7'], 'Especi...
variaveis         [{'id': 63, 'nome': 'IPCA - Variação mensal', ...
classificacoes    [{'id': 315, 'nome': 'Geral, grupo, subgrupo, ...
seriesbr.ibge.get_series(code, variables=None, start=None, end=None, last_n=None, municipalities=None, states=None, macroregions=None, microregions=None, mesoregions=None, brazil=None, classifications=None)[source]

Function to get variables associated with an aggregate from IBGE’s database.

Parameters:
  • code (int) – Aggregate’s code.
  • variables (int or list of ints, optional) – Which variables to select (if None, return all of them).
  • start (int or str, optional) – Initial date, month or day first.
  • end (int or str, optional) – Final date, month or day first.
  • last_n (int or str, optional) – Return only last n observations.
  • municipalities (str, int, bool a list, optional) – Municipalities’ codes.
  • states (str, int, bool or a list, optional) – States’ codes.
  • macroregions (str, int, bool or a list, optional) – Macroregions’ codes.
  • microregions (str, int, bool or a list, optional) – Microregions’ codes.
  • mesoregions (str, int, bool or a list, optional) – Mesoregions’ codes.
  • classifications (dict, int, str or list, optional) – Classifications’ / categories’ codes.
Returns:

A DataFrame with series values and metadata.

Return type:

pandas.DataFrame

Examples

>>> ibge.get_series(1419, start="11-2019", end="11-2019")
           Nível Territorial                               Variável Geral, grupo, subgrupo, item e subitem   Valor
Date
2019-11-01            Brasil                 IPCA - Variação mensal                           Índice geral    0.51
2019-11-01            Brasil       IPCA - Variação acumulada no ano                           Índice geral    3.12
2019-11-01            Brasil  IPCA - Variação acumulada em 12 meses                           Índice geral    3.27
2019-11-01            Brasil                     IPCA - Peso mensal                           Índice geral  100.00
seriesbr.ibge.list_cities(*search, **searches)[source]

Function to list all cities and their codes.

Parameters:
  • *search – Strings to search in cities’ names.
  • **searches – Strings to search in other columns.
Returns:

A DataFrame with the cities and their codes.

Return type:

pandas.DataFrame

Examples

>>> ibge.list_cities(UF_nome="Rio de Janeiro").head()
           id                nome  microrregiao_id       microrregiao_nome  mesorregiao_id     mesorregiao_nome  UF_id UF_sigla         UF_nome  regiao_id regiao_sigla regiao_nome
3175  3300100      Angra dos Reis            33013     Baía da Ilha Grande            3305       Sul Fluminense     33       RJ  Rio de Janeiro          3           SE     Sudeste
3176  3300159             Aperibé            33002  Santo Antônio de Pádua            3301  Noroeste Fluminense     33       RJ  Rio de Janeiro          3           SE     Sudeste
3177  3300209            Araruama            33010                   Lagos            3304             Baixadas     33       RJ  Rio de Janeiro          3           SE     Sudeste
3178  3300225               Areal            33005               Três Rios            3303    Centro Fluminense     33       RJ  Rio de Janeiro          3           SE     Sudeste
3179  3300233  Armação dos Búzios            33010                   Lagos            3304             Baixadas     33       RJ  Rio de Janeiro          3           SE     Sudeste
seriesbr.ibge.list_classifications(aggregate, *search, **searches)[source]

Function to list all classification of a given aggregate.

Parameters:
  • aggregate (int or str) – Aggregate’s code.
  • *search – Strings to search in categories’ names.
  • **searches – Strings to search in other columns.
Returns:

A DataFrame with the classifications and their categories.

Return type:

pandas.DataFrame

Examples

>>> ibge.list_classifications(1419).head()
     id                                     nome unidade  nivel classificacao_id                      classificacao_nome
0  7169                             Índice geral    None     -1              315  Geral, grupo, subgrupo, item e subitem
1  7170                  1.Alimentação e bebidas    None     -1              315  Geral, grupo, subgrupo, item e subitem
2  7171              11.Alimentação no domicílio    None     -1              315  Geral, grupo, subgrupo, item e subitem
3  7172  1101.Cereais, leguminosas e oleaginosas    None     -1              315  Geral, grupo, subgrupo, item e subitem
4  7173                            1101002.Arroz    None     -1              315  Geral, grupo, subgrupo, item e subitem
seriesbr.ibge.list_locations(aggregate)[source]

Function to list locations of a given aggregate.

Parameters:aggregate (int or str) – Aggregate’s code.
Returns:A DataFrame with the available locations for an aggregate.
Return type:pandas.DataFrame

Examples

>>> ibge.list_locations(1419)
  codes  parameters
0    N1      brazil
1    N6        city
2    N7  mesoregion
seriesbr.ibge.list_macroregions(*search, **searches)[source]

Function to list all macroregions and their codes.

Parameters:
  • *search – Strings to search in macroregions’ names.
  • **searches – Strings to search in other columns.
Returns:

A DataFrame with the macroregions and their codes.

Return type:

pandas.DataFrame

Examples

>>> ibge.list_macroregions()
   id sigla          nome
0   1     N         Norte
1   2    NE      Nordeste
2   3    SE       Sudeste
3   4     S           Sul
4   5    CO  Centro-Oeste
seriesbr.ibge.list_mesoregions(*search, **searches)[source]

Function to list all mesoregions and their codes.

Parameters:
  • *search – Strings to search in mesoregions’ names.
  • **searches – Strings to search in other columns.
Returns:

A DataFrame with metadata about the mesoregions.

Return type:

pandas.DataFrame

Examples

>>> ibge.list_mesoregions().head()
     id               nome  UF_id UF_sigla   UF_nome  regiao_id regiao_sigla regiao_nome
0  1101    Madeira-Guaporé     11       RO  Rondônia          1            N       Norte
1  1102  Leste Rondoniense     11       RO  Rondônia          1            N       Norte
2  1201      Vale do Juruá     12       AC      Acre          1            N       Norte
3  1202       Vale do Acre     12       AC      Acre          1            N       Norte
4  1301   Norte Amazonense     13       AM  Amazonas          1            N       Norte
seriesbr.ibge.list_microregions(*search, **searches)[source]

Function to list all microregions.

Parameters:
  • *search – Strings to search in microregions’ names.
  • **searches – Strings to search in other columns.
Returns:

A DataFrame with metadata about the microregions.

Return type:

pandas.DataFrame

Examples

>>> ibge.list_microregions("Rio", mesorregiao_nome="Rio")
        id                   nome  mesorregiao_id                 mesorregiao_nome  UF_id UF_sigla         UF_nome  regiao_id regiao_sigla regiao_nome
348  33018         Rio de Janeiro            3306  Metropolitana do Rio de Janeiro     33       RJ  Rio de Janeiro          3           SE     Sudeste
352  35004  São José do Rio Preto            3501            São José do Rio Preto     35       SP       São Paulo          3           SE     Sudeste
seriesbr.ibge.list_periods(aggregate)[source]

Function to list periods of a given aggregate.

Parameters:aggregate (int or str) – Aggregate’s code.
Returns:A DataFrame with the frequency, initial and final dates of an aggregate.
Return type:pandas.DataFrame

Examples

>>> ibge.list_periods(1419)
           valores
frequencia  mensal
inicio      201201
fim         201911
seriesbr.ibge.list_states(*search, **searches)[source]

Function to list all states and their codes.

Parameters:
  • aggregate (int or str) – Aggregate’s code.
  • *search – Strings to search in states’ names.
  • **searches – Strings to search in other columns.
Returns:

A DataFrame with the states and their codes.

Return type:

pandas.DataFrame

Examples

>>> ibge.list_states().head()
   id sigla      nome  regiao_id regiao_sigla regiao_nome
0  11    RO  Rondônia          1            N       Norte
1  12    AC      Acre          1            N       Norte
2  13    AM  Amazonas          1            N       Norte
3  14    RR   Roraima          1            N       Norte
4  15    PA      Pará          1            N       Norte
seriesbr.ibge.list_variables(aggregate, *search, **searches)[source]

Function to list all variables associated with an aggregate.

Parameters:
  • aggregate (int or str) – Aggregate’s code.
  • *search – Names to search for.
  • **searches – Strings to search in other columns.
Returns:

A DataFrame with all available variables of an aggregate.

Return type:

pandas.DataFrame

Examples

>>> ibge.list_variables(1419)
     id                               variavel unidade
0    63                 IPCA - Variação mensal       %
1    69       IPCA - Variação acumulada no ano       %
2  2265  IPCA - Variação acumulada em 12 meses       %
3    66                     IPCA - Peso mensal       %
seriesbr.ibge.search(*search, **searches)[source]

Function to list all aggregates in IBGE’s database.

Parameters:
  • *search – Strings to search in aggregates’ names.
  • **searches – Strings to search in other columns.
Returns:

A DataFrame with an aggregate’s metadata.

Return type:

pandas.DataFrame

Examples

>>> ibge.search("Índice", "Preços", pesquisa_nome="Pesquisa").head()
        id                                               nome pesquisa_id                              pesquisa_nome
2472  1399  Número de empresas comerciais, Unidades locais...          PB                 Pesquisa Anual de Comércio
2957   379  Índice de Gini - recebimento médio mensal das ...          OF          Pesquisa de Orçamentos Familiares
3101    50  Folha de pagamento nominal por classes de indú...          DG  Pesquisa Industrial Mensal - Dados Gerais
3102    49  Folha de pagamento nominal por tipo de índice ...          DG  Pesquisa Industrial Mensal - Dados Gerais
3103    52  Folha de pagamento nominal por trabalhador por...          DG  Pesquisa Industrial Mensal - Dados Gerais

seriesbr.ipea module

seriesbr.ipea.get_metadata(code)[source]

Get metadata of a series specified by the a code.

Parameters:code (int or str) –
Returns:A DataFrame with series’ metadata.
Return type:pandas.DataFrame

Examples

>>> ipea.get_metadata("BM12_TJOVER12").head()
                                                           values
SERCODIGO                                           BM12_TJOVER12
SERNOME                              Taxa de juros - Over / Selic
SERCOMENTARIO   Quadro: Taxas de juros efetivas.  Para 1974-19...
SERATUALIZACAO                      2019-12-17T05:06:00.793-02:00
BASNOME                                            Macroeconômico
seriesbr.ipea.get_serie(code, name=None, start=None, end=None)[source]

Auxiliary function to return a single time series from IPEA database.

seriesbr.ipea.get_series(*codes, start=None, end=None, **kwargs)[source]

Get multiple series into a DataFrame.

Parameters:
  • codes (dict, str) – Dictionary like {“name1”: code1, “name2”: code2} or a bunch of code strings, e.g. code1, code2.
  • start (str) – Initial date, month or day first.
  • end (str) – End date, month or day first.
  • **kwargs – Passed to pandas.concat.
Returns:

A DataFrame with series’ values.

Return type:

pandas.DataFrame

Examples

>>> ipea.get_series("BM12_TJOVER12", "CAGED12_SALDO12", start="2018", end="03-2018")
            BM12_TJOVER12  CAGED12_SALDO12
Date
2018-01-01           0.58          77822.0
2018-02-01           0.47          61188.0
2018-03-01           0.53          56151.0
seriesbr.ipea.list_countries()[source]

Function to list all countries available in the database.

Returns:A DataFrame with all available countries in IPEA’s database.
Return type:pandas.DataFrame

Examples

>>> ipea.list_countries().head()
  PAICODIGO         PAINOME
0       ZAF   África do Sul
1       DEU        Alemanha
2      LATI  América Latina
3       AGO          Angola
4       SAU  Arábia Saudita
seriesbr.ipea.list_metadata()[source]

Function to list all valid metadatas and their description.

Returns:
Return type:pandas.DataFrame

Examples

>>> ipea.list_metadata().head()
                   Description
SERNOME                   Name
SERCODIGO                 Code
PERNOME              Frequency
UNINOME    Unit of measurement
BASNOME           Basis's name
seriesbr.ipea.list_themes()[source]

Function to list all themes available in the database.

Returns:A DataFrame with all available themes in IPEA’s database.
Return type:pandas.DataFrame

Examples

>>> ipea.list_themes().head()
    TEMCODIGO  TEMCODIGO_PAI                  TEMNOME
0          28            NaN             Agropecuária
1          23            NaN       Assistência social
2          10            NaN    Balanço de pagamentos
3           7            NaN                   Câmbio
4           5            NaN        Comércio exterior
seriesbr.ipea.search(*SERNOME, **metadatas)[source]

Function to search in IPEA’s database.

Parameters:
  • *SERNOME – String(s) to look up for in a series’ name.
  • **metadatas – Keyword arguments where parameter is a valid metadata and value a str or list of str.
Returns:

A DataFrame with the search results.

Return type:

pandas.DataFrame

Examples

>>> ipea.search("Taxa", "Juros", "Selic", "recursos livres", PERNOME="mensal", UNINOME="%").head()
        SERCODIGO                                            SERNOME PERNOME   UNINOME
0    BM12_CRDTJ12  Operações de crédito - recursos direcionados -...  Mensal  (% a.a.)
1  BM12_CRDTJPF12  Operações de crédito - recursos direcionados -...  Mensal  (% a.a.)
2  BM12_CRDTJPJ12  Operações de crédito - recursos direcionados -...  Mensal  (% a.a.)
3    BM12_CRLIN12  Operações de crédito - recursos livres - inadi...  Mensal       (%)
4  BM12_CRLINPF12  Operações de crédito - recursos livres - inadi...  Mensal       (%)

seriesbr.seriesbr module

seriesbr.seriesbr.get_series(*codes, start=None, end=None, **kwargs)[source]

Get multiple series from both BCB or IPEA.

Parameters:
  • codes (dict, str, int) – Dictionary like {“name1”: cod1, “name2”: cod2} or a bunch of code numbers, e.g. cod1, cod2.
  • start (str, optional) – Initial date, month or day first.
  • end (str, optional) – End date, month or day first.
  • last_n (int, optional) – Ignore other arguments and get last n observations.
  • **kwargs – Passed to pandas.concat.
Returns:

A DataFrame with series’ values.

Return type:

pandas.DataFrame

Examples

>>> seriesbr.get_series("BM12_CRLIN12", 20786, start="2015", end="2015")
            BM12_CRLIN12  20786
Date
2015-01-01          4.41  26.91
2015-02-01          4.42  27.95
2015-03-01          4.38  27.72
2015-04-01          4.57  28.93
2015-05-01          4.68  29.61
2015-06-01          4.59  30.31
2015-07-01          4.77  31.24
2015-08-01          4.91  31.65
2015-09-01          4.92  31.49
2015-10-01          5.02  32.64
2015-11-01          5.22  33.31
2015-12-01          5.28  31.64