Created
March 17, 2020 19:05
-
-
Save nportinari/01a66a032cc8ab6f35d13c2bc65750c4 to your computer and use it in GitHub Desktop.
Calculadora_IPCA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "Calculadora_IPCA", | |
"provenance": [], | |
"collapsed_sections": [], | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"accelerator": "GPU" | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/nportinari/01a66a032cc8ab6f35d13c2bc65750c4/calculadora_ipca.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "su2JcYqW1n9m", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"import pandas as pd" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Pbya-EM_bohL", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"#Importa o arquivo do site do IBGE (dados até 11/2019, se quiser mais precisa mudar a URL)\n", | |
"ipca = pd.read_csv('https://sidra.ibge.gov.br/geratabela?format=us.csv&name=tabela1737.csv&terr=N&rank=-&query=t/1737/n1/all/v/2266/p/199312,199412,199512,199612,199712,199812,199912,200012,200112,200212,200312,200412,200512,200612,200712,200812,200912,201012,201112,201212,201312,201412,201512,201612,201712,201812,201911/d/v2266%2013/l/v,,t%2Bp', encoding = 'utf-8', delimiter = ',',skiprows=2)" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "I-RepuIbb8e_", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"#Limpa o arquivo\n", | |
"ipca = ipca.drop(columns=['Unnamed: 0'])\n", | |
"ipca['mes'], ipca['ano'] = ipca['Mês'].str.split(\" \",1).str \n", | |
"ipca = ipca.dropna(axis=0)" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "hnPDcZDedbQr", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"#Cria um dicionário com os valores base 100 por ano, desde 93\n", | |
"ipcadic = ipca.set_index('ano')['Unnamed: 2'].to_dict()" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "7yhfUgXcfZ6i", | |
"colab_type": "code", | |
"outputId": "4762beba-c65f-4699-a636-411d9af98126", | |
"colab": { | |
"base_uri": "https://localhost:8080/", | |
"height": 70 | |
} | |
}, | |
"source": [ | |
"ano_referencia = str(input('Digite o ano do valor a ser corrigido: '))\n", | |
"valor = float(input('Digite o valor a ser corrigido: '))\n", | |
"valor_corrigido_19 = (valor/ipcadic[ano_referencia])*ipcadic['2019'] \n", | |
"\n", | |
"print('Valor em 11/2019: ', valor_corrigido_19)" | |
], | |
"execution_count": 0, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": [ | |
"Digite o ano do valor a ser corrigido: 2007\n", | |
"Digite o valor a ser corrigido: 35\n", | |
"Valor em 2019: 67.39282916364648\n" | |
], | |
"name": "stdout" | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment