Created
May 12, 2023 23:14
-
-
Save mateuspestana/a3921b5f6f259fd8cf15c9c127b53f29 to your computer and use it in GitHub Desktop.
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
import streamlit as st | |
import pandas as pd | |
import requests | |
def baixaDeputados(idLegislatura): | |
url = 'https://dadosabertos.camara.leg.br/api/v2/deputados?idLegislatura=' + str(idLegislatura) | |
r = requests.get(url) | |
deputados = r.json()['dados'] | |
df = pd.DataFrame(deputados) | |
return df | |
st.title('Lista de Deputados em Exercício') | |
idLegislatura = st.slider('Escolha de qual legislatura você quer a lista de deputados', 50, 57, 57) | |
df = baixaDeputados(idLegislatura) | |
st.header('Lista de deputados') | |
st.write(df) | |
st.download_button('Baixar lista de deputados', data=df.to_csv(), file_name='deputados.csv', mime='text/csv') | |
st.header('Gráficos') | |
st.subheader('Número de deputados por partido') | |
st.bar_chart(df['siglaPartido'].value_counts()) | |
st.subheader('Número de deputados por estado') | |
st.bar_chart(df['siglaUf'].value_counts()) | |
st.header('Lista de deputados por estado') | |
coluna1, coluna2 = st.columns(2) | |
estado = coluna1.selectbox('Escolha um estado', sorted(df['siglaUf'].unique()), index=25) | |
partido = coluna2.selectbox('Escolha um partido', sorted(df['siglaPartido'].unique())) | |
df2 = df[(df['siglaUf'] == estado) & (df['siglaPartido'] == partido)] | |
st.markdown('---') | |
if df2.empty: | |
st.subheader(':no_entry_sign: Sem deputados nesse estado filiados a esse partido! :crying_cat_face:') | |
else: | |
for index, linha in df2.iterrows(): | |
with st.expander(linha['nome']): | |
st.image(linha['urlFoto'], width=130) | |
st.write('Nome: ' + linha['nome']) | |
st.write('Partido: ' + linha['siglaPartido']) | |
st.write('UF: ' + linha['siglaUf']) | |
st.write('ID: ' + str(linha['id'])) | |
st.write('Email: ' + str(linha['email'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment