brazilian-data


Namebrazilian-data JSON
Version 0.0.3 PyPI version JSON
download
home_pageNone
SummaryThis repository is part of the creation of a package for collecting Brazilian data
upload_time2024-08-12 01:01:11
maintainerNone
docs_urlNone
authorJeferson Sehnem
requires_pythonNone
licenseMIT License
keywords brazilian data
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <img src="https://raw.githubusercontent.com/Jeferson100/Data-Brasil/main/imagens/logo_brazilian.webp" alt="imagens" width="1000" height="700" />

[![Teste Actions](https://github.com/Jeferson100/Data-Brasil/actions/workflows/test.yml/badge.svg)](https://github.com/Jeferson100/Data-Brasil/actions/workflows/test.yml)
[![Coleta de Dados](https://github.com/Jeferson100/Data-Brasil/actions/workflows/datas.yml/badge.svg)](https://github.com/Jeferson100/Data-Brasil/actions/workflows/datas.yml)

# Brazilian Data

This repository is part of the development of a Python package designed for collecting data from Brazilian sources. It retrieves data from institutions such as the `Banco Central do Brasil`, `IBGE`, `IPEA`, and `FRED`.
To search for series from the sources, use the following websites.

- [Banco Central](https://www3.bcb.gov.br/sgspub/localizarseries/localizarSeries.do?method=prepararTelaLocalizarSeries)
- [IBGE](https://sidra.ibge.gov.br/home/ipca/brasil)
- [IPEA](http://www.ipeadata.gov.br/Default.aspx)
- [FRED](https://fred.stlouisfed.org/)


## Table of Contents

- [Installation](#installation)
- [How to import](#how-to-import)
- [EconomicData Class Documentation](#economicdata-class-documentation)
- [Brazilian_Data Usage](#brazilian_data-usage)
- [Contributing](#contributing)
- [License](#license)


## Installation

To install the package, execute the following command:
```	
pip install brazilian-data
```
## How to import

```python
from brazilian_data import EconomicData
```

# EconomicData Class Documentation

## Overview
The `EconomicData` class is designed to facilitate the fetching, processing, and saving of economic data from various sources such as Banco Central, IBGE, IPEADATA, and FRED.

## Initialization
### `__init__(self, codes_banco_central=None, codes_ibge=None, codes_ibge_link=None, codes_ipeadata=None, codes_fred=None, start_date=None)`
Initializes the `EconomicData` class with optional parameters for data codes and start date.

- **Parameters:**
  - `codes_banco_central` (dict): Dictionary of Banco Central codes.
  - `codes_ibge` (dict): Dictionary of IBGE codes.
  - `codes_ibge_link` (dict): Dictionary of IBGE links.
  - `codes_ipeadata` (dict): Dictionary of IPEADATA codes.
  - `codes_fred` (dict): Dictionary of FRED codes.
  - `start_date` (str): Start date for data fetching.

## Methods

### `fetch_data_for_code(self, link, column)`
Fetches data from an IBGE link for a specific column.

- **Parameters:**
  - `link` (str): URL link to fetch data from.
  - `column` (str): Column name to fetch data for.
- **Returns:** Data fetched from the specified link and column.

### `data_index(self)`
Generates a DataFrame with a date range starting from `start_date`.

- **Returns:** DataFrame with a date range as the index.

### `datas_banco_central(self, save=None, diretory=None, data_format=None)`
Fetches data from Banco Central and handles exceptions.

- **Parameters:**
  - `save` (bool): Whether to save the data.
  - `diretory` (str): Directory where the data will be saved.
  - `data_format` (str): Format to save the data ('csv', 'excel', 'json', 'pickle').
- **Returns:** DataFrame with Banco Central data if not saving.

### `datas_ibge(self, save=False, diretory=None, data_format=None)`
Fetches IBGE data and handles exceptions.

- **Parameters:**
  - `save` (bool): Whether to save the data.
  - `diretory` (str): Directory where the data will be saved.
  - `data_format` (str): Format to save the data ('csv', 'excel', 'json', 'pickle').
- **Returns:** DataFrame with IBGE data if not saving.

### `datas_ibge_link(self, save=None, diretory=None, data_format=None)`
Fetches data from IBGE links and handles exceptions.

- **Parameters:**
  - `save` (bool): Whether to save the data.
  - `diretory` (str): Directory where the data will be saved.
  - `data_format` (str): Format to save the data ('csv', 'excel', 'json', 'pickle').
- **Returns:** DataFrame with IBGE link data if not saving.

### `datas_ipeadata(self, salve=None, diretory=None, data_format=None)`
Fetches IPEADATA data and handles exceptions.

- **Parameters:**
  - `salve` (bool): Whether to save the data.
  - `diretory` (str): Directory where the data will be saved.
  - `data_format` (str): Format to save the data ('csv', 'excel', 'json', 'pickle').
- **Returns:** DataFrame with IPEADATA data if not saving.

### `datas_fred(self, save=None, diretory=None, data_format=None)`
Fetches data from FRED and handles exceptions.

- **Parameters:**
  - `save` (bool): Whether to save the data.
  - `diretory` (str): Directory where the data will be saved.
  - `data_format` (str): Format to save the data ('csv', 'excel', 'json', 'pickle').
- **Returns:** DataFrame with FRED data if not saving.

### `datas_brazil(self, datas_bcb=True, datas_ibge_codigos=True, datas_ibge_link=True, datas_ipeadata=True, datas_fred=False, missing_data=True, fill_method=None, save=None, directory=None, data_format=None)`
Fetches all data based on specified options.

- **Parameters:**
  - `datas_bcb` (bool): Whether to fetch Banco Central data.
  - `datas_ibge_codigos` (bool): Whether to fetch IBGE data by codes.
  - `datas_ibge_link` (bool): Whether to fetch IBGE data by links.
  - `datas_ipeadata` (bool): Whether to fetch IPEADATA data.
  - `datas_fred` (bool): Whether to fetch FRED data.
  - `missing_data` (bool): Whether to handle missing data.
  - `fill_method` (str): Method to handle missing data ('ffill' or 'bfill').
  - `save` (bool): Whether to save the data.
  - `directory` (str): Directory where the data will be saved.
  - `data_format` (str): Format to save the data ('csv', 'excel', 'json', 'pickle').
- **Returns:** DataFrame with all requested data if not saving.

### `save_datas(self, dados, diretory=None, data_format="csv")`
Saves the data to the specified directory and format.

- **Parameters:**
  - `dados` (DataFrame): DataFrame to be saved.
  - `diretory` (str): Directory where the data will be saved.
  - `data_format` (str): Format to save the data ('csv', 'excel', 'json', 'pickle').

### `help(self)`
Prints out information about the available methods and their usage.


- **Usage:** `instance.help()`

## Brazilian_Data Usage

### Initialization of the class

- **Parameters:** start_date

**The variable start_date defines the initial date for data collection.**

Example:
```python
start_date = "2020-01-01"
```

- **Parameters:** codes_banco_central

**The `codes_banco_central` should be a dictionary with the column name that the `datas_banco_central` function will recognize as the column name and the series code.**

Example:
```python
bcb_codes = {
    "selic": 4189,
    "cambio": 3698,
    "pib_mensal": 4380,
    "igp_m": 189,
    "igp_di": 190,
    "m1": 27788,
}
```

- **Parameters:** codes_ibge

The `codes_ibge` input should be a dictionary where each key represents the name of a variable (e.g., "ipca"), which the function will use as the column name. The value associated with each key should be another dictionary containing the following fields:

- `"codigo"`: An integer representing the code of the data series to be collected. This code is specific to the variable and identifies the series in the IBGE database.

- `"territorial_level"`: A string indicating the territorial level of the data, such as "1" for Brazil, "2" for regions, "3" for states, etc.

- `"ibge_territorial_code"`: A code defining the specific geographical area of the data. The value `"all"` indicates that data for all areas corresponding to the territorial level should be collected.

- `"variable"`: A string or number that identifies the specific variable within the data series. This may represent a specific category or indicator to be collected.

Example:

```python
variaveis_ibge = {
    "ipca": {
        "codigo": 1737,
        "territorial_level": "1",
        "ibge_territorial_code": "all",
        "variable": "63",
    }
}
```

- **Parameters:** codes_ibge_link

The `codes_ibge_link` input should be a dictionary where each key represents the name of an economic indicator or specific variable (e.g., "pib", "soja"), which the function will use as the column name. The value associated with each key is a URL that points to an Excel file available on the IBGE website, containing the data corresponding to that indicator.

These URLs are dynamically generated from the IBGE SIDRA system and can be used to download the tables directly. Each link contains specific parameters defining the selection of variables, periods, and territorial levels relevant to the query.

Example:

```python
    indicadores_ibge_link = {
    "capital_fixo": "https://sidra.ibge.gov.br/geratabela?format=xlsx&name=tabela5932.xlsx&terr=N&rank=-&query=t/5932/n1/all/v/6561/p/all/c11255/93406/d/v6561%201/l/v,p%2Bc11255,t",

    "soja": "https://sidra.ibge.gov.br/geratabela?format=xlsx&name=tabela6588.xlsx&terr=N&rank=-&query=t/6588/n1/all/v/35/p/all/c48/0,39443/l/v,p%2Bc48,t",}
```

These URLs allow for the direct download of the data in Excel format, which can then be processed by your code.

- **Parameters:** codes_ipeadata

**The `codes_ipeadata` should be a dictionary with the column name that the `datas_ipeadata` function will recognize as the column name and the series code.**

```python
codigos_ipeadata= {
    "taja_juros_ltn": "ANBIMA12_TJTLN1212",
    "imposto_renda": "SRF12_IR12",
    "ibovespa": "ANBIMA12_IBVSP12",
    "consumo_energia": "ELETRO12_CEET12",
    "brent_fob": "EIA366_PBRENT366",}
```

- **Parameters:** codes_fred

The `codes fred` should be a dictionary with the column name that the `datas_fred` function will recognize as the column name and the series code.

```python
codigos_fred = {
    "nasdaq100": "NASDAQ100",
    "taxa_cambio_efetiva": "RBBRBIS",
    "cboe_nasdaq": "VXNCLS",
    "taxa_juros_interbancaria": "IRSTCI01BRM156N",
    "atividade_economica_eua": "USPHCI",}
```	

### Method `datas_brazil`

For collecting data from different sources, you can use the `datas_brazil` method:

```python
## Import the `EconomicData` class
from brazilian_data import EconomicData

## Define parameters that will be used in the `datas_brazil` method
DATA_INICIO = "2000-01-01"

data_bcb = True
data_ibge = True
data_ibge_link = True
data_ipeadata = True
data_fred = False

## Initialize the `EconomicData` class
economic_brazil = EconomicData(codes_banco_central=variaveis_banco_central, 
                                 codes_ibge=variaveis_ibge, 
                                 codes_ipeadata=codigos_ipeadata, 
                                 codes_ibge_link=indicadores_ibge_link,
                                 start_date=DATA_INICIO)

## Call the `datas_brazil` method
dados = economic_brazil.datas_brazil(datas_bcb= data_bcb,
                                     datas_ibge_codigos=data_ibge, 
                                     datas_ibge_link=data_ibge_link, 
                                     datas_ipeadata=data_ipeadata,
                                     missing_data=True)
```
```python
dados.head()
```
<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>selic</th>
      <th>cambio</th>
      <th>pib_mensal</th>
      <th>igp_m</th>
      <th>igp_di</th>
      <th>m1</th>
      <th>ipca</th>
      <th>custo_m2</th>
      <th>pesquisa_industrial_mensal</th>
      <th>pib</th>
      <th>...</th>
      <th>capital_fixo</th>
      <th>producao_industrial_manufatureira</th>
      <th>soja</th>
      <th>milho_1</th>
      <th>milho_2</th>
      <th>taja_juros_ltn</th>
      <th>imposto_renda</th>
      <th>ibovespa</th>
      <th>consumo_energia</th>
      <th>brent_fob</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>2000-01-01</th>
      <td>18.94</td>
      <td>1.8037</td>
      <td>92576.6</td>
      <td>1.24</td>
      <td>1.02</td>
      <td>79015372.0</td>
      <td>0.62</td>
      <td>5.51</td>
      <td>69.71441</td>
      <td>1.4</td>
      <td>...</td>
      <td>-5.0</td>
      <td>57.43586</td>
      <td>52381672.0</td>
      <td>31477232.0</td>
      <td>10595844.0</td>
      <td>19.465261</td>
      <td>5043.680936</td>
      <td>-4.113276</td>
      <td>25060.0</td>
      <td>25.511000</td>
    </tr>
    <tr>
      <th>2000-02-01</th>
      <td>18.87</td>
      <td>1.7753</td>
      <td>91770.4</td>
      <td>0.35</td>
      <td>0.19</td>
      <td>79015372.0</td>
      <td>0.13</td>
      <td>5.51</td>
      <td>69.71441</td>
      <td>1.4</td>
      <td>...</td>
      <td>-5.0</td>
      <td>57.43586</td>
      <td>52381672.0</td>
      <td>31477232.0</td>
      <td>10595844.0</td>
      <td>19.465261</td>
      <td>4120.602582</td>
      <td>7.761777</td>
      <td>25057.0</td>
      <td>27.775714</td>
    </tr>
    <tr>
      <th>2000-03-01</th>
      <td>18.85</td>
      <td>1.7420</td>
      <td>92579.9</td>
      <td>0.15</td>
      <td>0.18</td>
      <td>79015372.0</td>
      <td>0.22</td>
      <td>5.51</td>
      <td>69.71441</td>
      <td>1.1</td>
      <td>...</td>
      <td>-0.3</td>
      <td>57.43586</td>
      <td>52381672.0</td>
      <td>31477232.0</td>
      <td>10595844.0</td>
      <td>19.465261</td>
      <td>5606.185192</td>
      <td>0.906002</td>
      <td>25662.0</td>
      <td>27.486087</td>
    </tr>
    <tr>
      <th>2000-04-01</th>
      <td>18.62</td>
      <td>1.7682</td>
      <td>91376.2</td>
      <td>0.23</td>
      <td>0.13</td>
      <td>79015372.0</td>
      <td>0.42</td>
      <td>5.51</td>
      <td>69.71441</td>
      <td>1.1</td>
      <td>...</td>
      <td>-0.3</td>
      <td>57.43586</td>
      <td>52381672.0</td>
      <td>31477232.0</td>
      <td>10595844.0</td>
      <td>19.465261</td>
      <td>4634.431697</td>
      <td>-12.811448</td>
      <td>25598.0</td>
      <td>22.764444</td>
    </tr>
    <tr>
      <th>2000-05-01</th>
      <td>18.51</td>
      <td>1.8279</td>
      <td>98727.0</td>
      <td>0.31</td>
      <td>0.67</td>
      <td>79015372.0</td>
      <td>0.01</td>
      <td>5.51</td>
      <td>69.71441</td>
      <td>1.1</td>
      <td>...</td>
      <td>-0.3</td>
      <td>57.43586</td>
      <td>52381672.0</td>
      <td>31477232.0</td>
      <td>10595844.0</td>
      <td>21.681500</td>
      <td>4047.302075</td>
      <td>-3.739461</td>
      <td>25448.0</td>
      <td>27.737619</td>
    </tr>
  </tbody>
</table>
<p>5 rows × 21 columns</p>
</div>

The `missing_data` parameter indicates whether missing values will be replaced using the `ffill` and `bfill` methods. By default, `missing_data` will be True, and missing values will be replaced. If you prefer to keep the missing data, set the `missing_data` parameter to `False`.

```python

## Import the `EconomicData` class
from brazilian_data import EconomicData

## Define parameters that will be used in the `datas_brazil` method
data_bcb = True
data_ibge = True
data_ibge_link = True
data_ipeadata = True
data_fred = False

## Initialize the `EconomicData` class
economic_brazil = EconomicData(codes_banco_central=variaveis_banco_central, 
                                 codes_ibge=variaveis_ibge, 
                                 codes_ipeadata=codigos_ipeadata, 
                                 codes_ibge_link=indicadores_ibge_link,
                                 start_date=DATA_INICIO)

## Call the `datas_brazil` method
dados = economic_brazil.datas_brazil(datas_bcb= data_bcb,
                                     datas_ibge_codigos=data_ibge, 
                                     datas_ibge_link=data_ibge_link, 
                                     datas_ipeadata=data_ipeadata,
                                     missing_data=False)
dados.head()
```
<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>cambio</th>
      <th>pib_mensal</th>
      <th>igp_m</th>
      <th>m1</th>
      <th>ipca</th>
      <th>custo_m2</th>
      <th>pesquisa_industrial_mensal</th>
      <th>pib</th>
      <th>despesas_publica</th>
      <th>capital_fixo</th>
      <th>producao_industrial_manufatureira</th>
      <th>soja</th>
      <th>milho_1</th>
      <th>milho_2</th>
      <th>taja_juros_ltn</th>
      <th>imposto_renda</th>
      <th>ibovespa</th>
      <th>consumo_energia</th>
      <th>brent_fob</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>2000-01-01</th>
      <td>1.8037</td>
      <td>92576.6</td>
      <td>1.24</td>
      <td>NaN</td>
      <td>0.62</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>1.4</td>
      <td>3.9</td>
      <td>-5.0</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>5043.680936</td>
      <td>-4.113276</td>
      <td>25060.0</td>
      <td>25.511000</td>
    </tr>
    <tr>
      <th>2000-02-01</th>
      <td>1.7753</td>
      <td>91770.4</td>
      <td>0.35</td>
      <td>NaN</td>
      <td>0.13</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>1.4</td>
      <td>3.9</td>
      <td>-5.0</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>4120.602582</td>
      <td>7.761777</td>
      <td>25057.0</td>
      <td>27.775714</td>
    </tr>
    <tr>
      <th>2000-03-01</th>
      <td>1.7420</td>
      <td>92579.9</td>
      <td>0.15</td>
      <td>NaN</td>
      <td>0.22</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>1.1</td>
      <td>3.6</td>
      <td>-0.3</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>5606.185192</td>
      <td>0.906002</td>
      <td>25662.0</td>
      <td>27.486087</td>
    </tr>
    <tr>
      <th>2000-04-01</th>
      <td>1.7682</td>
      <td>91376.2</td>
      <td>0.23</td>
      <td>NaN</td>
      <td>0.42</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>1.1</td>
      <td>3.6</td>
      <td>-0.3</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>19.465261</td>
      <td>4634.431697</td>
      <td>-12.811448</td>
      <td>25598.0</td>
      <td>22.764444</td>
    </tr>
    <tr>
      <th>2000-05-01</th>
      <td>1.8279</td>
      <td>98727.0</td>
      <td>0.31</td>
      <td>NaN</td>
      <td>0.01</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>1.1</td>
      <td>3.6</td>
      <td>-0.3</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>NaN</td>
      <td>21.681500</td>
      <td>4047.302075</td>
      <td>-3.739461</td>
      <td>25448.0</td>
      <td>27.737619</td>
    </tr>
  </tbody>
</table>
</div>

With the parameter `save=True`, you can download data. Define the `directory` parameter to save the file. If you don't define the `directory` parameter, an error will be returned. You can save in four formats: `csv`, `json`, `pickle`, and `excel`.

```python
## Import the `EconomicData` class
from brazilian_data import EconomicData

## Define parameters that will be used in the `datas_brazil` method
data_bcb = True
data_ibge = True
data_ibge_link = True
data_ipeadata = True
data_fred = False

## Initialize the `EconomicData` class
economic_brazil = EconomicData(codes_banco_central=variaveis_banco_central, 
                                 codes_ibge=variaveis_ibge, 
                                 codes_ipeadata=codigos_ipeadata, 
                                 codes_ibge_link=indicadores_ibge_link,
                                 start_date=DATA_INICIO)

## Call the `datas_brazil` method
dados = economic_brazil.datas_brazil(datas_bcb= data_bcb,
                                     datas_ibge_codigos=data_ibge, 
                                     datas_ibge_link=data_ibge_link, 
                                     datas_ipeadata=data_ipeadata,
                                     save=True,
                                     directory="../dados/economicos_brazil",
                                     data_format="csv")
```
This parameter will not return a dataframe, only the saved file. This parameter can be used for other methods in the class.

### Method `datas_banco_central`

If you want to download the data from the Banco Central, you can use the method `datas_banco_central`.

```python
## Imported library
from brazilian_data import EconomicData

## define the start date
DATA_INICIO = "2000-01-01"

## define the dictionary of codes
variaveis_banco_central= {
    "selic": 4189,
    "cambio": 3698,
    "pib_mensal": 4380,
    "igp_m": 189,
    "igp_di": 190,
    "m1": 27788,
}

## define a new object
economic_brazil = EconomicData(codes_banco_central=variaveis_banco_central, 
                                start_date=DATA_INICIO)

## download the data
dados = economic_brazil.datas_banco_central()
```	
```python
dados.head()
```
<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>selic</th>
      <th>pib_mensal</th>
      <th>igp_m</th>
      <th>igp_di</th>
      <th>m1</th>
    </tr>
    <tr>
      <th>Date</th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>2000-01-01</th>
      <td>18.94</td>
      <td>92576.6</td>
      <td>1.24</td>
      <td>1.02</td>
      <td>NaN</td>
    </tr>
    <tr>
      <th>2000-02-01</th>
      <td>18.87</td>
      <td>91770.4</td>
      <td>0.35</td>
      <td>0.19</td>
      <td>NaN</td>
    </tr>
    <tr>
      <th>2000-03-01</th>
      <td>18.85</td>
      <td>92579.9</td>
      <td>0.15</td>
      <td>0.18</td>
      <td>NaN</td>
    </tr>
    <tr>
      <th>2000-04-01</th>
      <td>18.62</td>
      <td>91376.2</td>
      <td>0.23</td>
      <td>0.13</td>
      <td>NaN</td>
    </tr>
    <tr>
      <th>2000-05-01</th>
      <td>18.51</td>
      <td>98727.0</td>
      <td>0.31</td>
      <td>0.67</td>
      <td>NaN</td>
    </tr>
  </tbody>
</table>
</div>

### Method `datas_ibge`

If you want to download the data from the IBGE, you can use the method `datas_ibge`.

```python
## Imported library
from brazilian_data import EconomicData

## define the start date
DATA_INICIO = "2010-01-01"

## define the dictionary of codes
variaveis_ibge = {
    "ipca": {
        "codigo": 1737,
        "territorial_level": "1",
        "ibge_territorial_code": "all",
        "variable": "63",
    },
    "custo_m2": {
        "codigo": 2296,
        "territorial_level": "1",
        "ibge_territorial_code": "all",
        "variable": "1198",
    },
    "pesquisa_industrial_mensal": {
        "codigo": 8159,
        "territorial_level": "1",
        "ibge_territorial_code": "all",
        "variable": "11599",
    },
    "pmc_volume": {
        "codigo": 8186,
        "territorial_level": "1",
        "ibge_territorial_code": "all",
        "variable": "11709",
    },
}

## define a new object
economic_brazil = EconomicData(codes_ibge=variaveis_ibge, start_date=DATA_INICIO)

## download the data
dados = economic_brazil.datas_ibge()
```

```python
dados.head()
```

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>ipca</th>
      <th>custo_m2</th>
      <th>pesquisa_industrial_mensal</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>2010-01-01</th>
      <td>0.75</td>
      <td>NaN</td>
      <td>91.20876</td>
    </tr>
    <tr>
      <th>2010-02-01</th>
      <td>0.78</td>
      <td>NaN</td>
      <td>88.95149</td>
    </tr>
    <tr>
      <th>2010-03-01</th>
      <td>0.52</td>
      <td>NaN</td>
      <td>105.07767</td>
    </tr>
    <tr>
      <th>2010-04-01</th>
      <td>0.57</td>
      <td>NaN</td>
      <td>99.30561</td>
    </tr>
    <tr>
      <th>2010-05-01</th>
      <td>0.43</td>
      <td>NaN</td>
      <td>104.27978</td>
    </tr>
  </tbody>
</table>
</div>

### Method `datas_ibge_link`

Some codes in `codes_ibge` do not work, resulting in errors and no files being returned. To address this, `codes_ibge_link` was created, where you obtain the link to the file from the [IBGE](https://sidra.ibge.gov.br/home/pms/brasil). A example of how to get the link is shown [here](https://github.com/Jeferson100/Data-Brasil/blob/main/imagens/example_link.md).

```python
## Imported library
from brazilian_data import EconomicData

## define the start date
DATA_INICIO = "2010-01-01"

## define the dictionary of codes
indicadores_ibge_link = {
    "capital_fixo": "https://sidra.ibge.gov.br/geratabela?format=xlsx&name=tabela5932.xlsx&terr=N&rank=-&query=t/5932/n1/all/v/6561/p/all/c11255/93406/d/v6561%201/l/v,p%2Bc11255,t",
    "producao_industrial_manufatureira": "https://sidra.ibge.gov.br/geratabela?format=xlsx&name=tabela8158.xlsx&terr=N&rank=-&query=t/8158/n1/all/v/11599/p/all/c543/129278/d/v11599%205/l/v,p%2Bc543,t",
    "soja": "https://sidra.ibge.gov.br/geratabela?format=xlsx&name=tabela6588.xlsx&terr=N&rank=-&query=t/6588/n1/all/v/35/p/all/c48/0,39443/l/v,p%2Bc48,t",
    "milho_1": "https://sidra.ibge.gov.br/geratabela?format=xlsx&name=tabela6588.xlsx&terr=N&rank=-&query=t/6588/n1/all/v/35/p/all/c48/0,39441/l/v,p%2Bc48,t",
    "milho_2": "https://sidra.ibge.gov.br/geratabela?format=xlsx&name=tabela6588.xlsx&terr=N&rank=-&query=t/6588/n1/all/v/35/p/all/c48/0,39442/l/v,p%2Bc48,t",
}

## define a new object
economic_brazil = EconomicData(codes_ibge_link=indicadores_ibge_link, 
                     start_date=DATA_INICIO)

## download the data
dados = economic_brazil.datas_ibge_link()
```
```python
dados.head()
```
<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>capital_fixo</th>
      <th>producao_industrial_manufatureira</th>
      <th>soja</th>
      <th>milho_1</th>
      <th>milho_2</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>2010-01-01</th>
      <td>12.9</td>
      <td>89.55269</td>
      <td>66137344.0</td>
      <td>33424815.0</td>
      <td>17996575.0</td>
    </tr>
    <tr>
      <th>2010-02-01</th>
      <td>12.9</td>
      <td>91.15047</td>
      <td>66941524.0</td>
      <td>33735243.0</td>
      <td>18620733.0</td>
    </tr>
    <tr>
      <th>2010-03-01</th>
      <td>29.0</td>
      <td>114.92197</td>
      <td>67350136.0</td>
      <td>33486684.0</td>
      <td>19095737.0</td>
    </tr>
    <tr>
      <th>2010-04-01</th>
      <td>29.0</td>
      <td>104.58762</td>
      <td>67913643.0</td>
      <td>33830625.0</td>
      <td>19457468.0</td>
    </tr>
    <tr>
      <th>2010-05-01</th>
      <td>29.0</td>
      <td>110.27518</td>
      <td>68131230.0</td>
      <td>33577605.0</td>
      <td>19569483.0</td>
    </tr>
  </tbody>
</table>
</div>

### Method `datas_ipeadata()`

If you want to download data from IPEA, you can use the `datas_ipeadata()` method.

```python	
## Import the `EconomicData` class
from brazilian_data import EconomicData

## Define parameters that will be used in the `datas_brazil` method
DATA_INICIO = "2010-01-01"

codigos_ipeadata= {
    "taja_juros_ltn": "ANBIMA12_TJTLN1212",
    "imposto_renda": "SRF12_IR12",
    "ibovespa": "ANBIMA12_IBVSP12",
    "consumo_energia": "ELETRO12_CEET12",
    "brent_fob": "EIA366_PBRENT366",
}

## define a new object
economic_brazil = EconomicData(codes_ipeadata=codigos_ipeadata, 
                                start_date=DATA_INICIO)

## download the data
dados = economic_brazil.datas_ipeadata()
```
```python
dados.head()
```
<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>taja_juros_ltn</th>
      <th>imposto_renda</th>
      <th>ibovespa</th>
      <th>consumo_energia</th>
      <th>brent_fob</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>2010-01-01</th>
      <td>10.454116</td>
      <td>22598.711556</td>
      <td>-4.65</td>
      <td>33360.0</td>
      <td>76.600323</td>
    </tr>
    <tr>
      <th>2010-02-01</th>
      <td>10.525189</td>
      <td>11801.791225</td>
      <td>1.68</td>
      <td>33730.0</td>
      <td>73.642143</td>
    </tr>
    <tr>
      <th>2010-03-01</th>
      <td>10.822181</td>
      <td>15204.637209</td>
      <td>5.82</td>
      <td>35117.0</td>
      <td>78.636452</td>
    </tr>
    <tr>
      <th>2010-04-01</th>
      <td>11.119986</td>
      <td>21267.690569</td>
      <td>-4.04</td>
      <td>35026.0</td>
      <td>84.191667</td>
    </tr>
    <tr>
      <th>2010-05-01</th>
      <td>11.696400</td>
      <td>14772.309694</td>
      <td>-6.64</td>
      <td>34297.0</td>
      <td>77.267742</td>
    </tr>
  </tbody>
</table>
</div>

### Method `datas_fred()`

If you want to download data from FRED, you can use the `datas_fred()` method. On the first use of `datas_fred()`	, a prompt will appear for setting up the FRED API key. To generate the key, follow the steps described [here](https://github.com/Jeferson100/Data-Brasil/blob/main/imagens/example_key_fred.md).

![fred](https://github.com/Jeferson100/Data-Brasil/blob/main/imagens/colocar_senha.png)

After that, you can run the code again and the data will be collected.

```python
## Import the `EconomicData` class
from brazilian_data import EconomicData

## Define parameters that will be used in the `datas_brazil` method
DATA_INICIO = "2010-01-01"

codigos_fred = {
    "nasdaq100": "NASDAQ100",
    "taxa_cambio_efetiva": "RBBRBIS",
    "cboe_nasdaq": "VXNCLS",
    "taxa_juros_interbancaria": "IRSTCI01BRM156N",
    "atividade_economica_eua": "USPHCI",}

## Initialize the `EconomicData` class
economic_brazil = EconomicData(codes_fred=codigos_fred, start_date=DATA_INICIO)

## Download the data
dados = economic_brazil.datas_fred()
```

```python
dados.head()
```
<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>nasdaq100</th>
      <th>taxa_cambio_efetiva</th>
      <th>cboe_nasdaq</th>
      <th>taxa_juros_interbancaria</th>
      <th>atividade_economica_eua</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>2010-01-01</th>
      <td>NaN</td>
      <td>160.61</td>
      <td>NaN</td>
      <td>8.75</td>
      <td>97.29</td>
    </tr>
    <tr>
      <th>2010-02-01</th>
      <td>1760.72</td>
      <td>157.74</td>
      <td>24.33</td>
      <td>8.75</td>
      <td>97.37</td>
    </tr>
    <tr>
      <th>2010-03-01</th>
      <td>1846.40</td>
      <td>162.82</td>
      <td>19.59</td>
      <td>8.75</td>
      <td>97.50</td>
    </tr>
    <tr>
      <th>2010-04-01</th>
      <td>1959.56</td>
      <td>166.02</td>
      <td>18.76</td>
      <td>8.80</td>
      <td>97.73</td>
    </tr>
    <tr>
      <th>2010-05-01</th>
      <td>NaN</td>
      <td>165.54</td>
      <td>NaN</td>
      <td>9.50</td>
      <td>98.19</td>
    </tr>
  </tbody>
</table>
</div>



## Contributing

All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome. 

## License

[MIT License](https://github.com/Jeferson100/Data-Brasil/blob/main/LICENSE)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "brazilian-data",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "Brazilian Data",
    "author": "Jeferson Sehnem",
    "author_email": "sehnemjeferson@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/6a/29/3bd1693e6fd5f54b7a2e683e9557becd87c7ded46b581b78b672e9dc4b7b/brazilian_data-0.0.3.tar.gz",
    "platform": null,
    "description": "<img src=\"https://raw.githubusercontent.com/Jeferson100/Data-Brasil/main/imagens/logo_brazilian.webp\" alt=\"imagens\" width=\"1000\" height=\"700\" />\n\n[![Teste Actions](https://github.com/Jeferson100/Data-Brasil/actions/workflows/test.yml/badge.svg)](https://github.com/Jeferson100/Data-Brasil/actions/workflows/test.yml)\n[![Coleta de Dados](https://github.com/Jeferson100/Data-Brasil/actions/workflows/datas.yml/badge.svg)](https://github.com/Jeferson100/Data-Brasil/actions/workflows/datas.yml)\n\n# Brazilian Data\n\nThis repository is part of the development of a Python package designed for collecting data from Brazilian sources. It retrieves data from institutions such as the `Banco Central do Brasil`, `IBGE`, `IPEA`, and `FRED`.\nTo search for series from the sources, use the following websites.\n\n- [Banco Central](https://www3.bcb.gov.br/sgspub/localizarseries/localizarSeries.do?method=prepararTelaLocalizarSeries)\n- [IBGE](https://sidra.ibge.gov.br/home/ipca/brasil)\n- [IPEA](http://www.ipeadata.gov.br/Default.aspx)\n- [FRED](https://fred.stlouisfed.org/)\n\n\n## Table of Contents\n\n- [Installation](#installation)\n- [How to import](#how-to-import)\n- [EconomicData Class Documentation](#economicdata-class-documentation)\n- [Brazilian_Data Usage](#brazilian_data-usage)\n- [Contributing](#contributing)\n- [License](#license)\n\n\n## Installation\n\nTo install the package, execute the following command:\n```\t\npip install brazilian-data\n```\n## How to import\n\n```python\nfrom brazilian_data import EconomicData\n```\n\n# EconomicData Class Documentation\n\n## Overview\nThe `EconomicData` class is designed to facilitate the fetching, processing, and saving of economic data from various sources such as Banco Central, IBGE, IPEADATA, and FRED.\n\n## Initialization\n### `__init__(self, codes_banco_central=None, codes_ibge=None, codes_ibge_link=None, codes_ipeadata=None, codes_fred=None, start_date=None)`\nInitializes the `EconomicData` class with optional parameters for data codes and start date.\n\n- **Parameters:**\n  - `codes_banco_central` (dict): Dictionary of Banco Central codes.\n  - `codes_ibge` (dict): Dictionary of IBGE codes.\n  - `codes_ibge_link` (dict): Dictionary of IBGE links.\n  - `codes_ipeadata` (dict): Dictionary of IPEADATA codes.\n  - `codes_fred` (dict): Dictionary of FRED codes.\n  - `start_date` (str): Start date for data fetching.\n\n## Methods\n\n### `fetch_data_for_code(self, link, column)`\nFetches data from an IBGE link for a specific column.\n\n- **Parameters:**\n  - `link` (str): URL link to fetch data from.\n  - `column` (str): Column name to fetch data for.\n- **Returns:** Data fetched from the specified link and column.\n\n### `data_index(self)`\nGenerates a DataFrame with a date range starting from `start_date`.\n\n- **Returns:** DataFrame with a date range as the index.\n\n### `datas_banco_central(self, save=None, diretory=None, data_format=None)`\nFetches data from Banco Central and handles exceptions.\n\n- **Parameters:**\n  - `save` (bool): Whether to save the data.\n  - `diretory` (str): Directory where the data will be saved.\n  - `data_format` (str): Format to save the data ('csv', 'excel', 'json', 'pickle').\n- **Returns:** DataFrame with Banco Central data if not saving.\n\n### `datas_ibge(self, save=False, diretory=None, data_format=None)`\nFetches IBGE data and handles exceptions.\n\n- **Parameters:**\n  - `save` (bool): Whether to save the data.\n  - `diretory` (str): Directory where the data will be saved.\n  - `data_format` (str): Format to save the data ('csv', 'excel', 'json', 'pickle').\n- **Returns:** DataFrame with IBGE data if not saving.\n\n### `datas_ibge_link(self, save=None, diretory=None, data_format=None)`\nFetches data from IBGE links and handles exceptions.\n\n- **Parameters:**\n  - `save` (bool): Whether to save the data.\n  - `diretory` (str): Directory where the data will be saved.\n  - `data_format` (str): Format to save the data ('csv', 'excel', 'json', 'pickle').\n- **Returns:** DataFrame with IBGE link data if not saving.\n\n### `datas_ipeadata(self, salve=None, diretory=None, data_format=None)`\nFetches IPEADATA data and handles exceptions.\n\n- **Parameters:**\n  - `salve` (bool): Whether to save the data.\n  - `diretory` (str): Directory where the data will be saved.\n  - `data_format` (str): Format to save the data ('csv', 'excel', 'json', 'pickle').\n- **Returns:** DataFrame with IPEADATA data if not saving.\n\n### `datas_fred(self, save=None, diretory=None, data_format=None)`\nFetches data from FRED and handles exceptions.\n\n- **Parameters:**\n  - `save` (bool): Whether to save the data.\n  - `diretory` (str): Directory where the data will be saved.\n  - `data_format` (str): Format to save the data ('csv', 'excel', 'json', 'pickle').\n- **Returns:** DataFrame with FRED data if not saving.\n\n### `datas_brazil(self, datas_bcb=True, datas_ibge_codigos=True, datas_ibge_link=True, datas_ipeadata=True, datas_fred=False, missing_data=True, fill_method=None, save=None, directory=None, data_format=None)`\nFetches all data based on specified options.\n\n- **Parameters:**\n  - `datas_bcb` (bool): Whether to fetch Banco Central data.\n  - `datas_ibge_codigos` (bool): Whether to fetch IBGE data by codes.\n  - `datas_ibge_link` (bool): Whether to fetch IBGE data by links.\n  - `datas_ipeadata` (bool): Whether to fetch IPEADATA data.\n  - `datas_fred` (bool): Whether to fetch FRED data.\n  - `missing_data` (bool): Whether to handle missing data.\n  - `fill_method` (str): Method to handle missing data ('ffill' or 'bfill').\n  - `save` (bool): Whether to save the data.\n  - `directory` (str): Directory where the data will be saved.\n  - `data_format` (str): Format to save the data ('csv', 'excel', 'json', 'pickle').\n- **Returns:** DataFrame with all requested data if not saving.\n\n### `save_datas(self, dados, diretory=None, data_format=\"csv\")`\nSaves the data to the specified directory and format.\n\n- **Parameters:**\n  - `dados` (DataFrame): DataFrame to be saved.\n  - `diretory` (str): Directory where the data will be saved.\n  - `data_format` (str): Format to save the data ('csv', 'excel', 'json', 'pickle').\n\n### `help(self)`\nPrints out information about the available methods and their usage.\n\n\n- **Usage:** `instance.help()`\n\n## Brazilian_Data Usage\n\n### Initialization of the class\n\n- **Parameters:** start_date\n\n**The variable start_date defines the initial date for data collection.**\n\nExample:\n```python\nstart_date = \"2020-01-01\"\n```\n\n- **Parameters:** codes_banco_central\n\n**The `codes_banco_central` should be a dictionary with the column name that the `datas_banco_central` function will recognize as the column name and the series code.**\n\nExample:\n```python\nbcb_codes = {\n    \"selic\": 4189,\n    \"cambio\": 3698,\n    \"pib_mensal\": 4380,\n    \"igp_m\": 189,\n    \"igp_di\": 190,\n    \"m1\": 27788,\n}\n```\n\n- **Parameters:** codes_ibge\n\nThe `codes_ibge` input should be a dictionary where each key represents the name of a variable (e.g., \"ipca\"), which the function will use as the column name. The value associated with each key should be another dictionary containing the following fields:\n\n- `\"codigo\"`: An integer representing the code of the data series to be collected. This code is specific to the variable and identifies the series in the IBGE database.\n\n- `\"territorial_level\"`: A string indicating the territorial level of the data, such as \"1\" for Brazil, \"2\" for regions, \"3\" for states, etc.\n\n- `\"ibge_territorial_code\"`: A code defining the specific geographical area of the data. The value `\"all\"` indicates that data for all areas corresponding to the territorial level should be collected.\n\n- `\"variable\"`: A string or number that identifies the specific variable within the data series. This may represent a specific category or indicator to be collected.\n\nExample:\n\n```python\nvariaveis_ibge = {\n    \"ipca\": {\n        \"codigo\": 1737,\n        \"territorial_level\": \"1\",\n        \"ibge_territorial_code\": \"all\",\n        \"variable\": \"63\",\n    }\n}\n```\n\n- **Parameters:** codes_ibge_link\n\nThe `codes_ibge_link` input should be a dictionary where each key represents the name of an economic indicator or specific variable (e.g., \"pib\", \"soja\"), which the function will use as the column name. The value associated with each key is a URL that points to an Excel file available on the IBGE website, containing the data corresponding to that indicator.\n\nThese URLs are dynamically generated from the IBGE SIDRA system and can be used to download the tables directly. Each link contains specific parameters defining the selection of variables, periods, and territorial levels relevant to the query.\n\nExample:\n\n```python\n    indicadores_ibge_link = {\n    \"capital_fixo\": \"https://sidra.ibge.gov.br/geratabela?format=xlsx&name=tabela5932.xlsx&terr=N&rank=-&query=t/5932/n1/all/v/6561/p/all/c11255/93406/d/v6561%201/l/v,p%2Bc11255,t\",\n\n    \"soja\": \"https://sidra.ibge.gov.br/geratabela?format=xlsx&name=tabela6588.xlsx&terr=N&rank=-&query=t/6588/n1/all/v/35/p/all/c48/0,39443/l/v,p%2Bc48,t\",}\n```\n\nThese URLs allow for the direct download of the data in Excel format, which can then be processed by your code.\n\n- **Parameters:** codes_ipeadata\n\n**The `codes_ipeadata` should be a dictionary with the column name that the `datas_ipeadata` function will recognize as the column name and the series code.**\n\n```python\ncodigos_ipeadata= {\n    \"taja_juros_ltn\": \"ANBIMA12_TJTLN1212\",\n    \"imposto_renda\": \"SRF12_IR12\",\n    \"ibovespa\": \"ANBIMA12_IBVSP12\",\n    \"consumo_energia\": \"ELETRO12_CEET12\",\n    \"brent_fob\": \"EIA366_PBRENT366\",}\n```\n\n- **Parameters:** codes_fred\n\nThe `codes fred` should be a dictionary with the column name that the `datas_fred` function will recognize as the column name and the series code.\n\n```python\ncodigos_fred = {\n    \"nasdaq100\": \"NASDAQ100\",\n    \"taxa_cambio_efetiva\": \"RBBRBIS\",\n    \"cboe_nasdaq\": \"VXNCLS\",\n    \"taxa_juros_interbancaria\": \"IRSTCI01BRM156N\",\n    \"atividade_economica_eua\": \"USPHCI\",}\n```\t\n\n### Method `datas_brazil`\n\nFor collecting data from different sources, you can use the `datas_brazil` method:\n\n```python\n## Import the `EconomicData` class\nfrom brazilian_data import EconomicData\n\n## Define parameters that will be used in the `datas_brazil` method\nDATA_INICIO = \"2000-01-01\"\n\ndata_bcb = True\ndata_ibge = True\ndata_ibge_link = True\ndata_ipeadata = True\ndata_fred = False\n\n## Initialize the `EconomicData` class\neconomic_brazil = EconomicData(codes_banco_central=variaveis_banco_central, \n                                 codes_ibge=variaveis_ibge, \n                                 codes_ipeadata=codigos_ipeadata, \n                                 codes_ibge_link=indicadores_ibge_link,\n                                 start_date=DATA_INICIO)\n\n## Call the `datas_brazil` method\ndados = economic_brazil.datas_brazil(datas_bcb= data_bcb,\n                                     datas_ibge_codigos=data_ibge, \n                                     datas_ibge_link=data_ibge_link, \n                                     datas_ipeadata=data_ipeadata,\n                                     missing_data=True)\n```\n```python\ndados.head()\n```\n<div>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>selic</th>\n      <th>cambio</th>\n      <th>pib_mensal</th>\n      <th>igp_m</th>\n      <th>igp_di</th>\n      <th>m1</th>\n      <th>ipca</th>\n      <th>custo_m2</th>\n      <th>pesquisa_industrial_mensal</th>\n      <th>pib</th>\n      <th>...</th>\n      <th>capital_fixo</th>\n      <th>producao_industrial_manufatureira</th>\n      <th>soja</th>\n      <th>milho_1</th>\n      <th>milho_2</th>\n      <th>taja_juros_ltn</th>\n      <th>imposto_renda</th>\n      <th>ibovespa</th>\n      <th>consumo_energia</th>\n      <th>brent_fob</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2000-01-01</th>\n      <td>18.94</td>\n      <td>1.8037</td>\n      <td>92576.6</td>\n      <td>1.24</td>\n      <td>1.02</td>\n      <td>79015372.0</td>\n      <td>0.62</td>\n      <td>5.51</td>\n      <td>69.71441</td>\n      <td>1.4</td>\n      <td>...</td>\n      <td>-5.0</td>\n      <td>57.43586</td>\n      <td>52381672.0</td>\n      <td>31477232.0</td>\n      <td>10595844.0</td>\n      <td>19.465261</td>\n      <td>5043.680936</td>\n      <td>-4.113276</td>\n      <td>25060.0</td>\n      <td>25.511000</td>\n    </tr>\n    <tr>\n      <th>2000-02-01</th>\n      <td>18.87</td>\n      <td>1.7753</td>\n      <td>91770.4</td>\n      <td>0.35</td>\n      <td>0.19</td>\n      <td>79015372.0</td>\n      <td>0.13</td>\n      <td>5.51</td>\n      <td>69.71441</td>\n      <td>1.4</td>\n      <td>...</td>\n      <td>-5.0</td>\n      <td>57.43586</td>\n      <td>52381672.0</td>\n      <td>31477232.0</td>\n      <td>10595844.0</td>\n      <td>19.465261</td>\n      <td>4120.602582</td>\n      <td>7.761777</td>\n      <td>25057.0</td>\n      <td>27.775714</td>\n    </tr>\n    <tr>\n      <th>2000-03-01</th>\n      <td>18.85</td>\n      <td>1.7420</td>\n      <td>92579.9</td>\n      <td>0.15</td>\n      <td>0.18</td>\n      <td>79015372.0</td>\n      <td>0.22</td>\n      <td>5.51</td>\n      <td>69.71441</td>\n      <td>1.1</td>\n      <td>...</td>\n      <td>-0.3</td>\n      <td>57.43586</td>\n      <td>52381672.0</td>\n      <td>31477232.0</td>\n      <td>10595844.0</td>\n      <td>19.465261</td>\n      <td>5606.185192</td>\n      <td>0.906002</td>\n      <td>25662.0</td>\n      <td>27.486087</td>\n    </tr>\n    <tr>\n      <th>2000-04-01</th>\n      <td>18.62</td>\n      <td>1.7682</td>\n      <td>91376.2</td>\n      <td>0.23</td>\n      <td>0.13</td>\n      <td>79015372.0</td>\n      <td>0.42</td>\n      <td>5.51</td>\n      <td>69.71441</td>\n      <td>1.1</td>\n      <td>...</td>\n      <td>-0.3</td>\n      <td>57.43586</td>\n      <td>52381672.0</td>\n      <td>31477232.0</td>\n      <td>10595844.0</td>\n      <td>19.465261</td>\n      <td>4634.431697</td>\n      <td>-12.811448</td>\n      <td>25598.0</td>\n      <td>22.764444</td>\n    </tr>\n    <tr>\n      <th>2000-05-01</th>\n      <td>18.51</td>\n      <td>1.8279</td>\n      <td>98727.0</td>\n      <td>0.31</td>\n      <td>0.67</td>\n      <td>79015372.0</td>\n      <td>0.01</td>\n      <td>5.51</td>\n      <td>69.71441</td>\n      <td>1.1</td>\n      <td>...</td>\n      <td>-0.3</td>\n      <td>57.43586</td>\n      <td>52381672.0</td>\n      <td>31477232.0</td>\n      <td>10595844.0</td>\n      <td>21.681500</td>\n      <td>4047.302075</td>\n      <td>-3.739461</td>\n      <td>25448.0</td>\n      <td>27.737619</td>\n    </tr>\n  </tbody>\n</table>\n<p>5 rows \u00d7 21 columns</p>\n</div>\n\nThe `missing_data` parameter indicates whether missing values will be replaced using the `ffill` and `bfill` methods. By default, `missing_data` will be True, and missing values will be replaced. If you prefer to keep the missing data, set the `missing_data` parameter to `False`.\n\n```python\n\n## Import the `EconomicData` class\nfrom brazilian_data import EconomicData\n\n## Define parameters that will be used in the `datas_brazil` method\ndata_bcb = True\ndata_ibge = True\ndata_ibge_link = True\ndata_ipeadata = True\ndata_fred = False\n\n## Initialize the `EconomicData` class\neconomic_brazil = EconomicData(codes_banco_central=variaveis_banco_central, \n                                 codes_ibge=variaveis_ibge, \n                                 codes_ipeadata=codigos_ipeadata, \n                                 codes_ibge_link=indicadores_ibge_link,\n                                 start_date=DATA_INICIO)\n\n## Call the `datas_brazil` method\ndados = economic_brazil.datas_brazil(datas_bcb= data_bcb,\n                                     datas_ibge_codigos=data_ibge, \n                                     datas_ibge_link=data_ibge_link, \n                                     datas_ipeadata=data_ipeadata,\n                                     missing_data=False)\ndados.head()\n```\n<div>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>cambio</th>\n      <th>pib_mensal</th>\n      <th>igp_m</th>\n      <th>m1</th>\n      <th>ipca</th>\n      <th>custo_m2</th>\n      <th>pesquisa_industrial_mensal</th>\n      <th>pib</th>\n      <th>despesas_publica</th>\n      <th>capital_fixo</th>\n      <th>producao_industrial_manufatureira</th>\n      <th>soja</th>\n      <th>milho_1</th>\n      <th>milho_2</th>\n      <th>taja_juros_ltn</th>\n      <th>imposto_renda</th>\n      <th>ibovespa</th>\n      <th>consumo_energia</th>\n      <th>brent_fob</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2000-01-01</th>\n      <td>1.8037</td>\n      <td>92576.6</td>\n      <td>1.24</td>\n      <td>NaN</td>\n      <td>0.62</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.4</td>\n      <td>3.9</td>\n      <td>-5.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>5043.680936</td>\n      <td>-4.113276</td>\n      <td>25060.0</td>\n      <td>25.511000</td>\n    </tr>\n    <tr>\n      <th>2000-02-01</th>\n      <td>1.7753</td>\n      <td>91770.4</td>\n      <td>0.35</td>\n      <td>NaN</td>\n      <td>0.13</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.4</td>\n      <td>3.9</td>\n      <td>-5.0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>4120.602582</td>\n      <td>7.761777</td>\n      <td>25057.0</td>\n      <td>27.775714</td>\n    </tr>\n    <tr>\n      <th>2000-03-01</th>\n      <td>1.7420</td>\n      <td>92579.9</td>\n      <td>0.15</td>\n      <td>NaN</td>\n      <td>0.22</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.1</td>\n      <td>3.6</td>\n      <td>-0.3</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>5606.185192</td>\n      <td>0.906002</td>\n      <td>25662.0</td>\n      <td>27.486087</td>\n    </tr>\n    <tr>\n      <th>2000-04-01</th>\n      <td>1.7682</td>\n      <td>91376.2</td>\n      <td>0.23</td>\n      <td>NaN</td>\n      <td>0.42</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.1</td>\n      <td>3.6</td>\n      <td>-0.3</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>19.465261</td>\n      <td>4634.431697</td>\n      <td>-12.811448</td>\n      <td>25598.0</td>\n      <td>22.764444</td>\n    </tr>\n    <tr>\n      <th>2000-05-01</th>\n      <td>1.8279</td>\n      <td>98727.0</td>\n      <td>0.31</td>\n      <td>NaN</td>\n      <td>0.01</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.1</td>\n      <td>3.6</td>\n      <td>-0.3</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>21.681500</td>\n      <td>4047.302075</td>\n      <td>-3.739461</td>\n      <td>25448.0</td>\n      <td>27.737619</td>\n    </tr>\n  </tbody>\n</table>\n</div>\n\nWith the parameter `save=True`, you can download data. Define the `directory` parameter to save the file. If you don't define the `directory` parameter, an error will be returned. You can save in four formats: `csv`, `json`, `pickle`, and `excel`.\n\n```python\n## Import the `EconomicData` class\nfrom brazilian_data import EconomicData\n\n## Define parameters that will be used in the `datas_brazil` method\ndata_bcb = True\ndata_ibge = True\ndata_ibge_link = True\ndata_ipeadata = True\ndata_fred = False\n\n## Initialize the `EconomicData` class\neconomic_brazil = EconomicData(codes_banco_central=variaveis_banco_central, \n                                 codes_ibge=variaveis_ibge, \n                                 codes_ipeadata=codigos_ipeadata, \n                                 codes_ibge_link=indicadores_ibge_link,\n                                 start_date=DATA_INICIO)\n\n## Call the `datas_brazil` method\ndados = economic_brazil.datas_brazil(datas_bcb= data_bcb,\n                                     datas_ibge_codigos=data_ibge, \n                                     datas_ibge_link=data_ibge_link, \n                                     datas_ipeadata=data_ipeadata,\n                                     save=True,\n                                     directory=\"../dados/economicos_brazil\",\n                                     data_format=\"csv\")\n```\nThis parameter will not return a dataframe, only the saved file. This parameter can be used for other methods in the class.\n\n### Method `datas_banco_central`\n\nIf you want to download the data from the Banco Central, you can use the method `datas_banco_central`.\n\n```python\n## Imported library\nfrom brazilian_data import EconomicData\n\n## define the start date\nDATA_INICIO = \"2000-01-01\"\n\n## define the dictionary of codes\nvariaveis_banco_central= {\n    \"selic\": 4189,\n    \"cambio\": 3698,\n    \"pib_mensal\": 4380,\n    \"igp_m\": 189,\n    \"igp_di\": 190,\n    \"m1\": 27788,\n}\n\n## define a new object\neconomic_brazil = EconomicData(codes_banco_central=variaveis_banco_central, \n                                start_date=DATA_INICIO)\n\n## download the data\ndados = economic_brazil.datas_banco_central()\n```\t\n```python\ndados.head()\n```\n<div>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>selic</th>\n      <th>pib_mensal</th>\n      <th>igp_m</th>\n      <th>igp_di</th>\n      <th>m1</th>\n    </tr>\n    <tr>\n      <th>Date</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2000-01-01</th>\n      <td>18.94</td>\n      <td>92576.6</td>\n      <td>1.24</td>\n      <td>1.02</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2000-02-01</th>\n      <td>18.87</td>\n      <td>91770.4</td>\n      <td>0.35</td>\n      <td>0.19</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2000-03-01</th>\n      <td>18.85</td>\n      <td>92579.9</td>\n      <td>0.15</td>\n      <td>0.18</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2000-04-01</th>\n      <td>18.62</td>\n      <td>91376.2</td>\n      <td>0.23</td>\n      <td>0.13</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2000-05-01</th>\n      <td>18.51</td>\n      <td>98727.0</td>\n      <td>0.31</td>\n      <td>0.67</td>\n      <td>NaN</td>\n    </tr>\n  </tbody>\n</table>\n</div>\n\n### Method `datas_ibge`\n\nIf you want to download the data from the IBGE, you can use the method `datas_ibge`.\n\n```python\n## Imported library\nfrom brazilian_data import EconomicData\n\n## define the start date\nDATA_INICIO = \"2010-01-01\"\n\n## define the dictionary of codes\nvariaveis_ibge = {\n    \"ipca\": {\n        \"codigo\": 1737,\n        \"territorial_level\": \"1\",\n        \"ibge_territorial_code\": \"all\",\n        \"variable\": \"63\",\n    },\n    \"custo_m2\": {\n        \"codigo\": 2296,\n        \"territorial_level\": \"1\",\n        \"ibge_territorial_code\": \"all\",\n        \"variable\": \"1198\",\n    },\n    \"pesquisa_industrial_mensal\": {\n        \"codigo\": 8159,\n        \"territorial_level\": \"1\",\n        \"ibge_territorial_code\": \"all\",\n        \"variable\": \"11599\",\n    },\n    \"pmc_volume\": {\n        \"codigo\": 8186,\n        \"territorial_level\": \"1\",\n        \"ibge_territorial_code\": \"all\",\n        \"variable\": \"11709\",\n    },\n}\n\n## define a new object\neconomic_brazil = EconomicData(codes_ibge=variaveis_ibge, start_date=DATA_INICIO)\n\n## download the data\ndados = economic_brazil.datas_ibge()\n```\n\n```python\ndados.head()\n```\n\n<div>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>ipca</th>\n      <th>custo_m2</th>\n      <th>pesquisa_industrial_mensal</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2010-01-01</th>\n      <td>0.75</td>\n      <td>NaN</td>\n      <td>91.20876</td>\n    </tr>\n    <tr>\n      <th>2010-02-01</th>\n      <td>0.78</td>\n      <td>NaN</td>\n      <td>88.95149</td>\n    </tr>\n    <tr>\n      <th>2010-03-01</th>\n      <td>0.52</td>\n      <td>NaN</td>\n      <td>105.07767</td>\n    </tr>\n    <tr>\n      <th>2010-04-01</th>\n      <td>0.57</td>\n      <td>NaN</td>\n      <td>99.30561</td>\n    </tr>\n    <tr>\n      <th>2010-05-01</th>\n      <td>0.43</td>\n      <td>NaN</td>\n      <td>104.27978</td>\n    </tr>\n  </tbody>\n</table>\n</div>\n\n### Method `datas_ibge_link`\n\nSome codes in `codes_ibge` do not work, resulting in errors and no files being returned. To address this, `codes_ibge_link` was created, where you obtain the link to the file from the [IBGE](https://sidra.ibge.gov.br/home/pms/brasil). A example of how to get the link is shown [here](https://github.com/Jeferson100/Data-Brasil/blob/main/imagens/example_link.md).\n\n```python\n## Imported library\nfrom brazilian_data import EconomicData\n\n## define the start date\nDATA_INICIO = \"2010-01-01\"\n\n## define the dictionary of codes\nindicadores_ibge_link = {\n    \"capital_fixo\": \"https://sidra.ibge.gov.br/geratabela?format=xlsx&name=tabela5932.xlsx&terr=N&rank=-&query=t/5932/n1/all/v/6561/p/all/c11255/93406/d/v6561%201/l/v,p%2Bc11255,t\",\n    \"producao_industrial_manufatureira\": \"https://sidra.ibge.gov.br/geratabela?format=xlsx&name=tabela8158.xlsx&terr=N&rank=-&query=t/8158/n1/all/v/11599/p/all/c543/129278/d/v11599%205/l/v,p%2Bc543,t\",\n    \"soja\": \"https://sidra.ibge.gov.br/geratabela?format=xlsx&name=tabela6588.xlsx&terr=N&rank=-&query=t/6588/n1/all/v/35/p/all/c48/0,39443/l/v,p%2Bc48,t\",\n    \"milho_1\": \"https://sidra.ibge.gov.br/geratabela?format=xlsx&name=tabela6588.xlsx&terr=N&rank=-&query=t/6588/n1/all/v/35/p/all/c48/0,39441/l/v,p%2Bc48,t\",\n    \"milho_2\": \"https://sidra.ibge.gov.br/geratabela?format=xlsx&name=tabela6588.xlsx&terr=N&rank=-&query=t/6588/n1/all/v/35/p/all/c48/0,39442/l/v,p%2Bc48,t\",\n}\n\n## define a new object\neconomic_brazil = EconomicData(codes_ibge_link=indicadores_ibge_link, \n                     start_date=DATA_INICIO)\n\n## download the data\ndados = economic_brazil.datas_ibge_link()\n```\n```python\ndados.head()\n```\n<div>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>capital_fixo</th>\n      <th>producao_industrial_manufatureira</th>\n      <th>soja</th>\n      <th>milho_1</th>\n      <th>milho_2</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2010-01-01</th>\n      <td>12.9</td>\n      <td>89.55269</td>\n      <td>66137344.0</td>\n      <td>33424815.0</td>\n      <td>17996575.0</td>\n    </tr>\n    <tr>\n      <th>2010-02-01</th>\n      <td>12.9</td>\n      <td>91.15047</td>\n      <td>66941524.0</td>\n      <td>33735243.0</td>\n      <td>18620733.0</td>\n    </tr>\n    <tr>\n      <th>2010-03-01</th>\n      <td>29.0</td>\n      <td>114.92197</td>\n      <td>67350136.0</td>\n      <td>33486684.0</td>\n      <td>19095737.0</td>\n    </tr>\n    <tr>\n      <th>2010-04-01</th>\n      <td>29.0</td>\n      <td>104.58762</td>\n      <td>67913643.0</td>\n      <td>33830625.0</td>\n      <td>19457468.0</td>\n    </tr>\n    <tr>\n      <th>2010-05-01</th>\n      <td>29.0</td>\n      <td>110.27518</td>\n      <td>68131230.0</td>\n      <td>33577605.0</td>\n      <td>19569483.0</td>\n    </tr>\n  </tbody>\n</table>\n</div>\n\n### Method `datas_ipeadata()`\n\nIf you want to download data from IPEA, you can use the `datas_ipeadata()` method.\n\n```python\t\n## Import the `EconomicData` class\nfrom brazilian_data import EconomicData\n\n## Define parameters that will be used in the `datas_brazil` method\nDATA_INICIO = \"2010-01-01\"\n\ncodigos_ipeadata= {\n    \"taja_juros_ltn\": \"ANBIMA12_TJTLN1212\",\n    \"imposto_renda\": \"SRF12_IR12\",\n    \"ibovespa\": \"ANBIMA12_IBVSP12\",\n    \"consumo_energia\": \"ELETRO12_CEET12\",\n    \"brent_fob\": \"EIA366_PBRENT366\",\n}\n\n## define a new object\neconomic_brazil = EconomicData(codes_ipeadata=codigos_ipeadata, \n                                start_date=DATA_INICIO)\n\n## download the data\ndados = economic_brazil.datas_ipeadata()\n```\n```python\ndados.head()\n```\n<div>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>taja_juros_ltn</th>\n      <th>imposto_renda</th>\n      <th>ibovespa</th>\n      <th>consumo_energia</th>\n      <th>brent_fob</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2010-01-01</th>\n      <td>10.454116</td>\n      <td>22598.711556</td>\n      <td>-4.65</td>\n      <td>33360.0</td>\n      <td>76.600323</td>\n    </tr>\n    <tr>\n      <th>2010-02-01</th>\n      <td>10.525189</td>\n      <td>11801.791225</td>\n      <td>1.68</td>\n      <td>33730.0</td>\n      <td>73.642143</td>\n    </tr>\n    <tr>\n      <th>2010-03-01</th>\n      <td>10.822181</td>\n      <td>15204.637209</td>\n      <td>5.82</td>\n      <td>35117.0</td>\n      <td>78.636452</td>\n    </tr>\n    <tr>\n      <th>2010-04-01</th>\n      <td>11.119986</td>\n      <td>21267.690569</td>\n      <td>-4.04</td>\n      <td>35026.0</td>\n      <td>84.191667</td>\n    </tr>\n    <tr>\n      <th>2010-05-01</th>\n      <td>11.696400</td>\n      <td>14772.309694</td>\n      <td>-6.64</td>\n      <td>34297.0</td>\n      <td>77.267742</td>\n    </tr>\n  </tbody>\n</table>\n</div>\n\n### Method `datas_fred()`\n\nIf you want to download data from FRED, you can use the `datas_fred()` method. On the first use of `datas_fred()`\t, a prompt will appear for setting up the FRED API key. To generate the key, follow the steps described [here](https://github.com/Jeferson100/Data-Brasil/blob/main/imagens/example_key_fred.md).\n\n![fred](https://github.com/Jeferson100/Data-Brasil/blob/main/imagens/colocar_senha.png)\n\nAfter that, you can run the code again and the data will be collected.\n\n```python\n## Import the `EconomicData` class\nfrom brazilian_data import EconomicData\n\n## Define parameters that will be used in the `datas_brazil` method\nDATA_INICIO = \"2010-01-01\"\n\ncodigos_fred = {\n    \"nasdaq100\": \"NASDAQ100\",\n    \"taxa_cambio_efetiva\": \"RBBRBIS\",\n    \"cboe_nasdaq\": \"VXNCLS\",\n    \"taxa_juros_interbancaria\": \"IRSTCI01BRM156N\",\n    \"atividade_economica_eua\": \"USPHCI\",}\n\n## Initialize the `EconomicData` class\neconomic_brazil = EconomicData(codes_fred=codigos_fred, start_date=DATA_INICIO)\n\n## Download the data\ndados = economic_brazil.datas_fred()\n```\n\n```python\ndados.head()\n```\n<div>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>nasdaq100</th>\n      <th>taxa_cambio_efetiva</th>\n      <th>cboe_nasdaq</th>\n      <th>taxa_juros_interbancaria</th>\n      <th>atividade_economica_eua</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>2010-01-01</th>\n      <td>NaN</td>\n      <td>160.61</td>\n      <td>NaN</td>\n      <td>8.75</td>\n      <td>97.29</td>\n    </tr>\n    <tr>\n      <th>2010-02-01</th>\n      <td>1760.72</td>\n      <td>157.74</td>\n      <td>24.33</td>\n      <td>8.75</td>\n      <td>97.37</td>\n    </tr>\n    <tr>\n      <th>2010-03-01</th>\n      <td>1846.40</td>\n      <td>162.82</td>\n      <td>19.59</td>\n      <td>8.75</td>\n      <td>97.50</td>\n    </tr>\n    <tr>\n      <th>2010-04-01</th>\n      <td>1959.56</td>\n      <td>166.02</td>\n      <td>18.76</td>\n      <td>8.80</td>\n      <td>97.73</td>\n    </tr>\n    <tr>\n      <th>2010-05-01</th>\n      <td>NaN</td>\n      <td>165.54</td>\n      <td>NaN</td>\n      <td>9.50</td>\n      <td>98.19</td>\n    </tr>\n  </tbody>\n</table>\n</div>\n\n\n\n## Contributing\n\nAll contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome. \n\n## License\n\n[MIT License](https://github.com/Jeferson100/Data-Brasil/blob/main/LICENSE)\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "This repository is part of the creation of a package for collecting Brazilian data",
    "version": "0.0.3",
    "project_urls": null,
    "split_keywords": [
        "brazilian",
        "data"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6a293bd1693e6fd5f54b7a2e683e9557becd87c7ded46b581b78b672e9dc4b7b",
                "md5": "c4b8cd34aeb3127cfab289efa70d6440",
                "sha256": "d5e968748336ec4848f3bbc2baae8640c6f5d2e722151d7efac1587d460cd800"
            },
            "downloads": -1,
            "filename": "brazilian_data-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "c4b8cd34aeb3127cfab289efa70d6440",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 25757,
            "upload_time": "2024-08-12T01:01:11",
            "upload_time_iso_8601": "2024-08-12T01:01:11.719277Z",
            "url": "https://files.pythonhosted.org/packages/6a/29/3bd1693e6fd5f54b7a2e683e9557becd87c7ded46b581b78b672e9dc4b7b/brazilian_data-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-12 01:01:11",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "brazilian-data"
}
        
Elapsed time: 0.41904s