Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

import streamlit as st
import pandas as pd
import plotly.express as px

df = pd.read_excel("BASE01.CREDITO.xlsx")

Comment on lines +5 to +7
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pd.read_excel("BASE01.CREDITO.xlsx") relies on the current working directory; when running streamlit run .../Streamlit/Codes/part_03_streamlit_excel_tabs_charts.py from the repo root this file is not found (the dataset lives under .../Streamlit/Datasets/ and .../Datasets/). Use a path built relative to __file__ (e.g., Path(__file__).parent.parent / "Datasets" / ...) or provide a st.file_uploader so the app works regardless of where it’s launched from.

Suggested change
df = pd.read_excel("BASE01.CREDITO.xlsx")
from pathlib import Path
script_dir = Path(__file__).resolve().parent
excel_name = "BASE01.CREDITO.xlsx"
excel_candidates = [
script_dir.parent / "Datasets" / excel_name,
script_dir.parent.parent / "Datasets" / excel_name,
]
excel_path = next((path for path in excel_candidates if path.exists()), excel_candidates[0])
df = pd.read_excel(excel_path)

Copilot uses AI. Check for mistakes.
Comment on lines +6 to +7
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Excel read happens at the top level, so Streamlit will re-read the file on every rerun (widget interaction, code change), which can noticeably slow the app. Wrap the load in a small function decorated with st.cache_data (and optionally accept a path argument) so the data is cached across reruns.

Suggested change
df = pd.read_excel("BASE01.CREDITO.xlsx")
@st.cache_data
def load_data(path="BASE01.CREDITO.xlsx"):
return pd.read_excel(path)
df = load_data()

Copilot uses AI. Check for mistakes.
df_media_sexo = (
df[["sexo", "valorcredito"]]
.groupby(by=["sexo"])
.sum()
.reset_index()
)
Comment on lines +8 to +13
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name df_media_sexo suggests a mean/average (“média”), but the aggregation is .sum(). Rename the variable to match the aggregation (e.g., soma/total) or change the aggregation to .mean() if the intention is an average, to avoid misleading future readers.

Copilot uses AI. Check for mistakes.

st.title("Layout: Sidebar, Colunas e Abas")
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The page title says "Sidebar, Colunas e Abas", but this script only demonstrates tabs/charts (no st.sidebar or st.columns). Consider updating the title to reflect the actual layout being used so the UI description matches the content.

Suggested change
st.title("Layout: Sidebar, Colunas e Abas")
st.title("Layout: Abas e Gráficos")

Copilot uses AI. Check for mistakes.


# ABAS
aba1, aba2, aba3, aba4 = st.tabs(
["Tabela", "Estatísticas", "Gráfico", "Pizza"]
)
with aba1:
st.dataframe(df)
with aba2:
st.write(df.describe())
with aba3:
st.bar_chart(data=df_media_sexo, x="sexo", y="valorcredito")
with aba4:
fig = px.pie(
df_media_sexo,
names="sexo",
values="valorcredito",
color_discrete_sequence=["red", "blue"],
)
st.plotly_chart(fig)