{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "ProjetoVoluntarioCienciadeDados-GeoanaliseBarragenseMunicipios.ipynb", "version": "0.3.2", "provenance": [], "collapsed_sections": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" } }, "cells": [ { "metadata": { "id": "0aXmroRgxweJ", "colab_type": "text" }, "cell_type": "markdown", "source": [ "# **Projeto Voluntário de Ciência de Dados**\n", "\n" ] }, { "metadata": { "id": "omtPsGaQLc7y", "colab_type": "text" }, "cell_type": "markdown", "source": [ "> Autores: Eduardo Magallhães, \n", "Olivan Rodriguez(ponha seu nome aqui)\n", "\n", "> Versão: v0.1\n", "\n", "## MVP inicial do projeto\n", "\n", "\n", "\n", "> **1. Objetivos**\n", "\n", "\n", " * Montar uma base única dos dados de localização das barragens e municípios próximos\n", " * Realizar análise exploratória simples, com foco em sumarizar estatísticas\n", " * Criar um data-viz baseado em geolocalização\n", "\n", "\n", "\n", "> **2. Fontes de dados base**: ANA (Agência Nacional das Águas), Geolocalização dos municípios, ...\n", "\n", "> **3. Restrições**: Foco apenas nas barragens de mineração (já serão mais de 600!)\n", "\n", "> **4. Output**: Inicial, a ideia será mostrar a localização das barragens com maior risco/não inspecionadas e sua distância do(s) município(s).\n" ] }, { "metadata": { "id": "_Q6uBXxH544g", "colab_type": "text" }, "cell_type": "markdown", "source": [ "# Papéis no projeto:\n", "\n", "\n", "\n", "\n", "\n" ] }, { "metadata": { "id": "EYYHLYvYLiLS", "colab_type": "text" }, "cell_type": "markdown", "source": [ "\n", "\n", ">**Data Engineer**\n", "\n", "\n", " 1. Consolidar a(s) base(s) em um formato csv que possa ser lido pelo Pandas - \n", " Voluntário(s):Edu Magalhães, Olivan Rodriguez.\n", " \n", " 2. Formatar as geolocalizações (colocar as latitudes e longitudes no formato consumível pelo Kepler)\n", " Voluntário(s): Márcio Santos\n", "\n", "> **Cientista de Dados (Tech)**\n", "\n", " 1. Análise exploratória (sumário estatístico) que poderá ser usado pra ter insights ou ajudar na visualização/clusterização geolocalizada\n", " Voluntário(s):\n", "\n", ">**Cientista de Dados (Business)**\n", "\n", " 1. Organização da iniciativa\n", " Voluntário(s):Edu Magalhães, \n", " \n", " 2. Data-viz no Kepler ou ferramenta/biblioteca de geolocalização\n", " Voluntário(s):\n", " \n" ] }, { "metadata": { "id": "UQ61rQvbENye", "colab_type": "text" }, "cell_type": "markdown", "source": [ "# Prazos (para não ficarmos sem meta alguma, rsrs!)\n", "\n", "\n", "\n", "1. **Domingo, 03/fev** MVP inicial com pelo menos as barragens de Minas geolocalizadas em alguma ferramenta de data-viz\n", "\n", "\n" ] }, { "metadata": { "id": "2E83mlz3FPQz", "colab_type": "text" }, "cell_type": "markdown", "source": [ "\n", "\n", "---\n", "\n" ] }, { "metadata": { "id": "9iO-ZH_i2uKf", "colab_type": "text" }, "cell_type": "markdown", "source": [ "# 0.0 - Set up" ] }, { "metadata": { "id": "kkh0sMul2tbX", "colab_type": "code", "outputId": "d60d618b-4bfe-4c26-bd94-fcf9fe4f4657", "colab": { "base_uri": "https://localhost:8080/", "height": 34 } }, "cell_type": "code", "source": [ "!ls\n", "!pip install -q pydrive" ], "execution_count": 0, "outputs": [ { "output_type": "stream", "text": [ "adc.json database_versao_01_fonteANM_23_01_2019.csv sample_data\n" ], "name": "stdout" } ] }, { "metadata": { "id": "coP_MnIn22_O", "colab_type": "code", "colab": {} }, "cell_type": "code", "source": [ "from google.colab import auth\n", "auth.authenticate_user()\n", "\n", "from pydrive.drive import GoogleDrive\n", "from pydrive.auth import GoogleAuth\n", "from oauth2client.client import GoogleCredentials\n", "gauth = GoogleAuth()\n", "gauth.credentials = GoogleCredentials.get_application_default()\n", "drive = GoogleDrive(gauth)" ], "execution_count": 0, "outputs": [] }, { "metadata": { "id": "anwVXZOe241x", "colab_type": "code", "colab": {} }, "cell_type": "code", "source": [ "myfile = drive.CreateFile({'id': '1SdzbEMB6GXd2yaF-4KuEyMtB1JBtVsgI'})\n", "myfile.GetContentFile('database_versao_01_fonteANM_23_01_2019.csv')" ], "execution_count": 0, "outputs": [] }, { "metadata": { "id": "keVRl-vc26X-", "colab_type": "code", "colab": {} }, "cell_type": "code", "source": [ "#Imporatando as bibliotecas\n", "import numpy as np\n", "import pandas as pd\n", "\n", "import seaborn as sns\n", "import matplotlib.pyplot as plt\n", "from pandas import DataFrame, Series\n", "%matplotlib inline\n", "import calendar\n" ], "execution_count": 0, "outputs": [] }, { "metadata": { "id": "wfsmI_fTFVbc", "colab_type": "text" }, "cell_type": "markdown", "source": [ "# 1.0 Carregando os dados" ] }, { "metadata": { "id": "hy08nCVqFfwU", "colab_type": "text" }, "cell_type": "markdown", "source": [ "> **Links úteis das princiapis fontes de dados utilizadas:**\n", "\n", "\n", ">1. Arquivos das barragens no site do antigo **DNPM** (Departamento Nacional de Produção Mineral, agora **ANM**-Agência Nacional de Mineração) - http://www.anm.gov.br/assuntos/barragens/arquivos-barragens\n", ">> Nesse emaranhado de links, utilizaremos apenas o arquivo pdf do link http://www.anm.gov.br/assuntos/barragens/arquivos-barragens/CADASTRO%20NACIONAL%20DE%20BARRAGENS_2016%20_FINAL%2006-01-2017.pdf/view\n", ">>Tal arquivo nos ajudará a entender as colunas de classificação já geradas, porém, não deve ser muito mais útil que isso por estar em pdf (dificuldade de extrair os dados)\n", "\n", ">2. Inventário de barragens no site da **FEAM**, que é a Fundação Estadual do Meio Ambiente e, por isso, teremos apenas os dados das barragens de MG nesse site/repositório: http://www.feam.br/monitoramento/gestao-de-barragens\n", ">> Aqui, vamos utilizar o link http://www.feam.br/images/stories/2018/BARRAGENS/PLANILHA_DIVULGA%C3%87%C3%83O.xlsx para baixar a planilha com as informações das barragens.\n", ">> Nesse link, temos um relatório bem legal fazendo uma análise exploratória de dados que pode ser melhorada e mais explorada, além de depois podermos cruzar com mais dados, segue o link de referência: http://www.feam.br/images/stories/2018/BARRAGENS/Invent%C3%A1rio_de_Barragens_2017.pdf\n", "\n", ">3 Dados extras\n", ">> Dados sismológicos de acesso publico: http://obsis.unb.br/portalsis/ e http://www.sismo.iag.usp.br/eq/latest\n", "\n", ">4 Arquivos excel/csv (convertidos do pdf do item 1.)\n", ">>**Excel convertido originalmente**\n", "https://docs.google.com/spreadsheets/d/1Ntj0jr3joIJtnjZQqA9m7Qa-cgya1KiGjjng8mrT_KQ/edit?usp=sharing\n", "\n", ">>**CSV a partir do Excel**\n", "https://drive.google.com/file/d/1eb5C6_7LOiLvlhU7KXmvHaQ6Soa7E9EV/view?usp=sharing\n", "\n" ] }, { "metadata": { "id": "KHpLW0Oki-fb", "colab_type": "text" }, "cell_type": "markdown", "source": [ "## 1.1 Importando a planilha excel do cadastro nacional de barragens Fonte ANM" ] }, { "metadata": { "id": "Mtq4AhBM3FVq", "colab_type": "code", "colab": {} }, "cell_type": "code", "source": [ "pd.options.display.float_format = '{:,.2f}'.format\n", "\n", "df = pd.read_csv('database_versao_01_fonteANM_23_01_2019.csv', header=0, delimiter=',',encoding = 'utf-8', decimal= ',')" ], "execution_count": 0, "outputs": [] }, { "metadata": { "id": "9zuZP-5M0_Hw", "colab_type": "text" }, "cell_type": "markdown", "source": [ "## 1.2 - Primeiros olhares na base de dados e estatística simples/descritiva" ] }, { "metadata": { "id": "4_0uIgA2m-1A", "colab_type": "code", "outputId": "0ce4e77d-ee9c-483b-813d-b06b4f2e4266", "colab": { "base_uri": "https://localhost:8080/", "height": 309 } }, "cell_type": "code", "source": [ "df.head()" ], "execution_count": 0, "outputs": [ { "output_type": "execute_result", "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
NOME_BARRAGEM_MINERACAONOME_DO_EMPREENDEDORCPF_CNPJPOSICIONAMENTOUFMUNICIPIOMINERIO_PRINCIPALALTURA_ATUAL_metrosVOLUME_ATUAL_m3CATEGORIA_DE_RISCODANO_POTENCIAL_ASSOCIADOCLASSEINSERIDA_NA_PNSBLATITUDELONGITUDE
00-1Mineração Taboca S.a.34.019.992/0001-10Sul do EquadorAMPRESIDENTE FIGUEIREDOMinério de Estanho Primário22.0027,700,000.00BaixaMédiaCSim0.733361111111111-60.1383888888889
1103 (Cruz)Mineração Taboca S.a.34.019.992/0001-10Sul do EquadorAMPRESIDENTE FIGUEIREDOMinério de Estanho Primário10.30924,000.00BaixaMédiaCSim0.785722222222222-60.1419166666667
2111 (Índio)Mineração Taboca S.a.34.019.992/0001-10Sul do EquadorAMPRESIDENTE FIGUEIREDOMinério de Estanho Primário5.0048,873.00BaixaMédiaCSim0.789666666666667-60.1442777777778
3158 (A-1)Mineração Taboca S.a.34.019.992/0001-10Sul do EquadorAMPRESIDENTE FIGUEIREDOMinério de Estanho Primário30.0053,380,000.00BaixaAltaBSim0.738027777777778-60.0789166666667
4161 (A-2)Mineração Taboca S.a.34.019.992/0001-10Sul do EquadorAMPRESIDENTE FIGUEIREDOMinério de Estanho Primário22.001,018,054.00BaixaMédiaCSim0.732286944444444-60.0689988888889
\n", "
" ], "text/plain": [ " NOME_BARRAGEM_MINERACAO NOME_DO_EMPREENDEDOR CPF_CNPJ \\\n", "0 0-1 Mineração Taboca S.a. 34.019.992/0001-10 \n", "1 103 (Cruz) Mineração Taboca S.a. 34.019.992/0001-10 \n", "2 111 (Índio) Mineração Taboca S.a. 34.019.992/0001-10 \n", "3 158 (A-1) Mineração Taboca S.a. 34.019.992/0001-10 \n", "4 161 (A-2) Mineração Taboca S.a. 34.019.992/0001-10 \n", "\n", " POSICIONAMENTO UF MUNICIPIO MINERIO_PRINCIPAL \\\n", "0 Sul do Equador AM PRESIDENTE FIGUEIREDO Minério de Estanho Primário \n", "1 Sul do Equador AM PRESIDENTE FIGUEIREDO Minério de Estanho Primário \n", "2 Sul do Equador AM PRESIDENTE FIGUEIREDO Minério de Estanho Primário \n", "3 Sul do Equador AM PRESIDENTE FIGUEIREDO Minério de Estanho Primário \n", "4 Sul do Equador AM PRESIDENTE FIGUEIREDO Minério de Estanho Primário \n", "\n", " ALTURA_ATUAL_metros VOLUME_ATUAL_m3 CATEGORIA_DE_RISCO \\\n", "0 22.00 27,700,000.00 Baixa \n", "1 10.30 924,000.00 Baixa \n", "2 5.00 48,873.00 Baixa \n", "3 30.00 53,380,000.00 Baixa \n", "4 22.00 1,018,054.00 Baixa \n", "\n", " DANO_POTENCIAL_ASSOCIADO CLASSE INSERIDA_NA_PNSB LATITUDE \\\n", "0 Média C Sim 0.733361111111111 \n", "1 Média C Sim 0.785722222222222 \n", "2 Média C Sim 0.789666666666667 \n", "3 Alta B Sim 0.738027777777778 \n", "4 Média C Sim 0.732286944444444 \n", "\n", " LONGITUDE \n", "0 -60.1383888888889 \n", "1 -60.1419166666667 \n", "2 -60.1442777777778 \n", "3 -60.0789166666667 \n", "4 -60.0689988888889 " ] }, "metadata": { "tags": [] }, "execution_count": 53 } ] }, { "metadata": { "id": "-AwSkFAknAA_", "colab_type": "code", "outputId": "7c97bd54-3100-49de-cbac-df804cd404a6", "colab": { "base_uri": "https://localhost:8080/", "height": 34 } }, "cell_type": "code", "source": [ "# Formato da tabela\n", "df.shape" ], "execution_count": 0, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "(714, 15)" ] }, "metadata": { "tags": [] }, "execution_count": 54 } ] }, { "metadata": { "id": "07Lb9HZTwt14", "colab_type": "code", "outputId": "ebe4a08c-1098-40b3-ad3e-7bb56aa0fc3c", "colab": { "base_uri": "https://localhost:8080/", "height": 210 } }, "cell_type": "code", "source": [ "#Breve estatística descritiva\n", "df.describe(include=['object'])" ], "execution_count": 0, "outputs": [ { "output_type": "execute_result", "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
NOME_BARRAGEM_MINERACAONOME_DO_EMPREENDEDORCPF_CNPJPOSICIONAMENTOUFMUNICIPIOMINERIO_PRINCIPALALTURA_ATUAL_metrosVOLUME_ATUAL_m3CATEGORIA_DE_RISCODANO_POTENCIAL_ASSOCIADOCLASSEINSERIDA_NA_PNSBLATITUDELONGITUDE
count714714714714714714714714714390390390714714714
unique714233228220164572075913352704695
topBacia de Acumulação 01Mineracao Rio do Norte S A04.932.216/0001-46Sul do EquadorMGPOCONÉMinério de Ferro5.0012,000.00BaixaAltaBSim-19.41065-47.9556833333333
freq1252570532431210421033219719639036
\n", "
" ], "text/plain": [ " NOME_BARRAGEM_MINERACAO NOME_DO_EMPREENDEDOR \\\n", "count 714 714 \n", "unique 714 233 \n", "top Bacia de Acumulação 01 Mineracao Rio do Norte S A \n", "freq 1 25 \n", "\n", " CPF_CNPJ POSICIONAMENTO UF MUNICIPIO MINERIO_PRINCIPAL \\\n", "count 714 714 714 714 714 \n", "unique 228 2 20 164 57 \n", "top 04.932.216/0001-46 Sul do Equador MG POCONÉ Minério de Ferro \n", "freq 25 705 324 31 210 \n", "\n", " ALTURA_ATUAL_metros VOLUME_ATUAL_m3 CATEGORIA_DE_RISCO \\\n", "count 714 714 390 \n", "unique 207 591 3 \n", "top 5.00 12,000.00 Baixa \n", "freq 42 10 332 \n", "\n", " DANO_POTENCIAL_ASSOCIADO CLASSE INSERIDA_NA_PNSB LATITUDE \\\n", "count 390 390 714 714 \n", "unique 3 5 2 704 \n", "top Alta B Sim -19.41065 \n", "freq 197 196 390 3 \n", "\n", " LONGITUDE \n", "count 714 \n", "unique 695 \n", "top -47.9556833333333 \n", "freq 6 " ] }, "metadata": { "tags": [] }, "execution_count": 55 } ] }, { "metadata": { "id": "gTq68iKktFC2", "colab_type": "text" }, "cell_type": "markdown", "source": [ "" ] }, { "metadata": { "id": "Bb3tJPZFxHSd", "colab_type": "code", "outputId": "0c9e4871-ae96-4c65-f3b2-818b59c2fe70", "colab": { "base_uri": "https://localhost:8080/", "height": 289 } }, "cell_type": "code", "source": [ "# Checando dados nulos\n", "# Infelizmente temos dados nulos em algumas colunas... temos que verificar a causa disso.\n", "df.isnull().sum()" ], "execution_count": 0, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "NOME_BARRAGEM_MINERACAO 0\n", "NOME_DO_EMPREENDEDOR 0\n", "CPF_CNPJ 0\n", "POSICIONAMENTO 0\n", "UF 0\n", "MUNICIPIO 0\n", "MINERIO_PRINCIPAL 0\n", "ALTURA_ATUAL_metros 0\n", "VOLUME_ATUAL_m3 0\n", "CATEGORIA_DE_RISCO 324\n", "DANO_POTENCIAL_ASSOCIADO 324\n", "CLASSE 324\n", "INSERIDA_NA_PNSB 0\n", "LATITUDE 0\n", "LONGITUDE 0\n", "dtype: int64" ] }, "metadata": { "tags": [] }, "execution_count": 56 } ] }, { "metadata": { "id": "bsVGyWa63gRQ", "colab_type": "text" }, "cell_type": "markdown", "source": [ "# 2.0 - Primeiras explorações" ] }, { "metadata": { "id": "3aTbXkWr4yaY", "colab_type": "code", "outputId": "e40c2629-3dec-46f7-f345-04e7631d14e3", "colab": { "base_uri": "https://localhost:8080/", "height": 34 } }, "cell_type": "code", "source": [ "#Eliminando as linhas nulas para ficar mais fácil uma primeira análise\n", "df_nonullvalues = df.dropna(axis=0, how='any', thresh=None, subset=None, inplace=False)\n", "df_nonullvalues.shape" ], "execution_count": 0, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "(390, 15)" ] }, "metadata": { "tags": [] }, "execution_count": 57 } ] }, { "metadata": { "id": "W59PeyQF5SnJ", "colab_type": "code", "outputId": "698fd6ca-e535-480e-f93c-824c0f3c2b77", "colab": { "base_uri": "https://localhost:8080/", "height": 289 } }, "cell_type": "code", "source": [ "#Checando novamente a eliminação de valores nulos\n", "df_nonullvalues.isnull().sum()" ], "execution_count": 0, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "NOME_BARRAGEM_MINERACAO 0\n", "NOME_DO_EMPREENDEDOR 0\n", "CPF_CNPJ 0\n", "POSICIONAMENTO 0\n", "UF 0\n", "MUNICIPIO 0\n", "MINERIO_PRINCIPAL 0\n", "ALTURA_ATUAL_metros 0\n", "VOLUME_ATUAL_m3 0\n", "CATEGORIA_DE_RISCO 0\n", "DANO_POTENCIAL_ASSOCIADO 0\n", "CLASSE 0\n", "INSERIDA_NA_PNSB 0\n", "LATITUDE 0\n", "LONGITUDE 0\n", "dtype: int64" ] }, "metadata": { "tags": [] }, "execution_count": 58 } ] }, { "metadata": { "id": "6i58GYaRAHP_", "colab_type": "code", "colab": {} }, "cell_type": "code", "source": [ "#... continua...mandem bala quem quiser!" ], "execution_count": 0, "outputs": [] }, { "metadata": { "id": "AmvKvEu4FXG4", "colab_type": "code", "colab": {} }, "cell_type": "code", "source": [ "" ], "execution_count": 0, "outputs": [] } ] }