-
-
Save biamuniz/d9cf55b0c4d7ea422f6c97942ad8c37e to your computer and use it in GitHub Desktop.
Baixa e concatena os dados de multas ambientais aplicadas pelo Ibama
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
# Importando as bibliotecas necessarias | |
import pandas as pd | |
#mostrar todas as colunas da base | |
pd.set_option('display.max_columns', None) | |
#para lidar com o certificado de segurança | |
import ssl | |
ssl._create_default_https_context = ssl._create_unverified_context | |
UFS = ["AC","AL","AM","AP","BA","CE","DF","ES","GO","MA","MT","MS","MG","PA","PB","PE","PI","PR","RS","RJ","RR","RN","RO","SP","TO","SC","SE"] | |
urls = [] | |
for uf in UFS: | |
url = "http://dadosabertos.ibama.gov.br/dados/SICAFI/" + uf + "/Quantidade/multasDistribuidasBensTutelados.csv" | |
urls.append(url) | |
for item in urls: | |
# Leitura dos dados do arquivo CSV | |
df = pd.read_csv(item, sep=";", encoding="utf-8", on_bad_lines='skip') | |
# Definição do nome do objeto a partir do nome do arquivo CSV | |
obj_name = item.split('/')[5] | |
# Criação do objeto com nome diferente | |
globals()[obj_name] = df | |
BRASIL = pd.concat([AC,AL,AM,AP,BA,CE,DF,ES,GO,MA,MT,MS,MG,PA,PB,PE,PI,PR,RS,RJ,RR,RN,RO,SP,TO,SC,SE]) | |
BRASIL.to_excel("multas2003.xlsx") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment