Spaces:
Build error
Build error
Paginas
#1
by Pegumenezes - opened
pagina 1
DELETED
|
@@ -1,72 +0,0 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import pandas as pd
|
| 3 |
-
import seaborn as sns
|
| 4 |
-
import matplotlib.pyplot as plt
|
| 5 |
-
|
| 6 |
-
st.set_page_config(page_title="Visão Geral da Carteira", layout="wide")
|
| 7 |
-
|
| 8 |
-
st.title("📊 Visão Geral da Carteira de Crédito")
|
| 9 |
-
|
| 10 |
-
@st.cache_data
|
| 11 |
-
def load_data():
|
| 12 |
-
# Carrega os dados originais
|
| 13 |
-
url = 'https://raw.githubusercontent.com/pegumzs/Prova-final-siep/main/credit_customers.csv'
|
| 14 |
-
df = pd.read_csv(url)
|
| 15 |
-
return df
|
| 16 |
-
|
| 17 |
-
df = load_data()
|
| 18 |
-
|
| 19 |
-
# --- KPIs ---
|
| 20 |
-
total_clientes = len(df)
|
| 21 |
-
taxa_inadimplencia = (df['class'] == 'bad').mean() * 100
|
| 22 |
-
valor_medio_credito = df['credit_amount'].mean()
|
| 23 |
-
|
| 24 |
-
col1, col2, col3 = st.columns(3)
|
| 25 |
-
col1.metric("Total de Clientes", f"{total_clientes}")
|
| 26 |
-
col2.metric("Taxa de Inadimplência", f"{taxa_inadimplencia:.2f}%")
|
| 27 |
-
col3.metric("Valor Médio de Crédito", f"R$ {valor_medio_credito:,.2f}")
|
| 28 |
-
|
| 29 |
-
st.markdown("---")
|
| 30 |
-
|
| 31 |
-
# --- Filtros Interativos ---
|
| 32 |
-
st.sidebar.header("Filtros Interativos")
|
| 33 |
-
idade_min, idade_max = int(df['age'].min()), int(df['age'].max())
|
| 34 |
-
selected_age = st.sidebar.slider(
|
| 35 |
-
"Filtrar por Idade",
|
| 36 |
-
min_value=idade_min,
|
| 37 |
-
max_value=idade_max,
|
| 38 |
-
value=(idade_min, idade_max)
|
| 39 |
-
)
|
| 40 |
-
|
| 41 |
-
purpose_list = ['Todos'] + sorted(df['purpose'].unique().tolist())
|
| 42 |
-
selected_purpose = st.sidebar.selectbox(
|
| 43 |
-
"Filtrar por Propósito do Crédito",
|
| 44 |
-
purpose_list
|
| 45 |
-
)
|
| 46 |
-
|
| 47 |
-
# Aplicando filtros
|
| 48 |
-
df_filtered = df[
|
| 49 |
-
(df['age'] >= selected_age[0]) & (df['age'] <= selected_age[1])
|
| 50 |
-
]
|
| 51 |
-
if selected_purpose != 'Todos':
|
| 52 |
-
df_filtered = df_filtered[df_filtered['purpose'] == selected_purpose]
|
| 53 |
-
|
| 54 |
-
# --- Gráficos e Tabela ---
|
| 55 |
-
st.subheader("Análise Exploratória Interativa")
|
| 56 |
-
|
| 57 |
-
col1, col2 = st.columns(2)
|
| 58 |
-
|
| 59 |
-
with col1:
|
| 60 |
-
fig, ax = plt.subplots()
|
| 61 |
-
sns.histplot(df_filtered, x='credit_amount', hue='class', kde=True, ax=ax, palette=['#5cb85c', '#d9534f'])
|
| 62 |
-
ax.set_title("Distribuição do Valor do Crédito")
|
| 63 |
-
st.pyplot(fig)
|
| 64 |
-
|
| 65 |
-
with col2:
|
| 66 |
-
fig, ax = plt.subplots()
|
| 67 |
-
sns.countplot(data=df_filtered, y='credit_history', hue='class', palette=['#5cb85c', '#d9534f'])
|
| 68 |
-
ax.set_title("Contagem por Histórico de Crédito")
|
| 69 |
-
st.pyplot(fig)
|
| 70 |
-
|
| 71 |
-
st.subheader("Dados Filtrados")
|
| 72 |
-
st.dataframe(df_filtered)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|