Skip to content
Project_SWS_Dams
  • AI Chat
  • Code
  • Report
  • Spinner
    # Start coding here... 

    Dams in Brazil

    The aim of this short project is to display and investigate the data about dams in Brazil using python and its libraries. We'll be using the open data from SNISB (portuguese acronym for National System for Information about Safety of Dams).

    # 1st step: importing the libraries
    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    #The database is a csv file with two 'titles'. It will be imported using pandas and with the 3rd row as header:
    #another argument that I had to add: explain that in my db the decimal is ',' instead of the default '.'
    
    dams_br_raw = pd.read_csv('relatorio_barragens.csv', encoding='latin-1', sep=';', header=2, decimal=',') 
    
    #Displaying main information:
    dams_br_raw.info()
    dams_br_raw.head()
    print(list(dams_br_raw.columns))
    

    From the raw database, we can see that we have 40 columns, 23810 dams registered and lots of missing data. But we also can see that we can organize these dams according to its content (or main use), to location, to risk and damage.

    In order to get a cleaner chart, we'll remove some of the columns that won't be used or that don't have much information:

    dams_br = dams_br_raw.drop(['Nome_Secundário ','Tipo_Empreendedor','Código_Barragem_Fiscalizador ','Número_da_Autorização   ', 'Possui_PAE','Comprimento_Coroamento_m','Uso_Complementar','Data_da_Última_Fiscalização   ','Curso_Dágua_Barrado ','Nome_Curso_dágua ','Nível_de_Perigo_Global ','Possui_Eclusa'], axis=1)
    dams_br

    In Brazil, there are 26 states and one federal district. We can visualize the distribution of dams according to its estate:

    #Creating a new variable to filter dams per state:
    dams_UF = dams_br['UF']
    dams_UF
    
    UFs = dams_br.groupby('UF').size() 
    print(UFs)
    
    UFs.plot.bar()

    Would you like to see the data for a specific state?

    list_UFs = ("AC", "AL", "AP","AM","BA","CE" ,"DF" ,"ES" ,"GO" ,"MA", "MT", "MS", "MG" ,"PA" ,"PB","PR", "PE", "PI", "RJ", "RN" ,"RS", "RO" ,"RR" ,"SC", "SP", "SE", "TO")
    print('The abbreviations for the brazilian states are: ' + str(list_UFs))
    # state = input('Choose one of the states above: ') 
    
    ## I intended to ask for an input but it does not work in this pllatform. So I'll test the code with the input 'MG':
    state = 'SP'
    print(state)
    #Filtering the charts 
    dams_state = dams_br.groupby('UF').get_group(state)
    dams_state
    

    Now we have a new chart, named 'dams_state', with only the information about the dams in the state you've chosen before. What can we know about this state?