File size: 2,324 Bytes
26c9797
 
 
 
b38417a
26c9797
 
 
 
 
 
b38417a
 
 
 
 
26c9797
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6db5c38
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import streamlit as st
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from pathlib import Path

st.title("Penguin Dataset Explorer with Seaborn")

# Load the dataset


# Determine the absolute path to the CSV file
csv_path = Path(__file__).parent / "penguins.csv"

# Read the CSV file
df = pd.read_csv(csv_path)


# Sidebar filters
st.sidebar.header("Filters")

species_filter = st.sidebar.multiselect(
    "Select Species",
    options=df["species"].unique(),
    default=df["species"].unique()
)

sex_filter = st.sidebar.multiselect(
    "Select Sex",
    options=df["sex"].unique(),
    default=df["sex"].unique()
)

# Data Filtering
df_filtered = df[df["species"].isin(species_filter)]
df_filtered = df_filtered[df_filtered["sex"].isin(sex_filter)]


# Display data
st.subheader("Filtered Penguin Data")
st.dataframe(df_filtered.sample(10))


# Plotting options
st.subheader("Visualizations")

if not df_filtered.empty:
    st.write("---")

    # Histogram of bill length
    st.subheader("Bill Length Distribution")
    fig_bill_length = plt.figure()
    sns.histplot(df_filtered["bill_length_mm"], kde=True)
    plt.xlabel("Bill Length (mm)")
    plt.ylabel("Frequency")
    plt.title("Bill Length Distribution of Penguins")
    st.pyplot(fig_bill_length)

    st.write("---")

    # Scatter plot of bill length vs. flipper length
    st.subheader("Bill Length vs. Flipper Length")
    fig_bill_flipper = plt.figure()
    sns.scatterplot(x="bill_length_mm", y="flipper_length_mm", data=df_filtered)
    plt.xlabel("Bill Length (mm)")
    plt.ylabel("Flipper Length (mm)")
    plt.title("Bill Length vs Flipper Length")
    st.pyplot(fig_bill_flipper)

    st.write("---")

    # Boxplot of bill length by species
    st.subheader("Bill Length by Species")
    fig_bill_species = plt.figure()
    sns.boxplot(x="species", y="bill_length_mm", data=df_filtered)
    plt.xlabel("Species")
    plt.ylabel("Bill Length (mm)")
    plt.title("Bill Length by Species")
    st.pyplot(fig_bill_species)


else:
    st.warning("No data to display after applying filters. Adjust filters or the dataset.")


st.sidebar.markdown("Data Source: [Seaborn Penguin Dataset](https://seaborn.pydata.org/tutorial/penguins.html)")