Spaces:
Sleeping
Sleeping
Commit
·
fc7d0e7
1
Parent(s):
06b9c8f
Add a university demographics page
Browse files- app.py +7 -2
- page_demographics.py +26 -0
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
import page_home
|
3 |
import page_likert
|
|
|
4 |
from urllib.parse import quote, unquote
|
5 |
|
6 |
# Default to wide mode
|
@@ -15,9 +16,11 @@ if 'page' not in st.session_state:
|
|
15 |
|
16 |
# Sidebar navigation using buttons
|
17 |
st.sidebar.title("Navigation")
|
18 |
-
if st.sidebar.button("
|
19 |
st.session_state['page'] = 'Home'
|
20 |
-
if st.sidebar.button("
|
|
|
|
|
21 |
st.session_state['page'] = 'Likert'
|
22 |
|
23 |
# Update the query parameters based on the session state
|
@@ -28,6 +31,8 @@ if st.session_state['page'] == 'Home':
|
|
28 |
page_home.show()
|
29 |
elif st.session_state['page'] == 'Likert':
|
30 |
page_likert.show()
|
|
|
|
|
31 |
|
32 |
# Rerun Calculations
|
33 |
if st.sidebar.button("Rerun Calculations"):
|
|
|
1 |
import streamlit as st
|
2 |
import page_home
|
3 |
import page_likert
|
4 |
+
import page_demographics
|
5 |
from urllib.parse import quote, unquote
|
6 |
|
7 |
# Default to wide mode
|
|
|
16 |
|
17 |
# Sidebar navigation using buttons
|
18 |
st.sidebar.title("Navigation")
|
19 |
+
if st.sidebar.button("Introduction"):
|
20 |
st.session_state['page'] = 'Home'
|
21 |
+
if st.sidebar.button("Demographics"):
|
22 |
+
st.session_state['page'] = 'Demographics'
|
23 |
+
if st.sidebar.button("Student Attitudes"):
|
24 |
st.session_state['page'] = 'Likert'
|
25 |
|
26 |
# Update the query parameters based on the session state
|
|
|
31 |
page_home.show()
|
32 |
elif st.session_state['page'] == 'Likert':
|
33 |
page_likert.show()
|
34 |
+
elif st.session_state['page'] == 'Demographics':
|
35 |
+
page_demographics.show()
|
36 |
|
37 |
# Rerun Calculations
|
38 |
if st.sidebar.button("Rerun Calculations"):
|
page_demographics.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from datasets import load_dataset
|
4 |
+
|
5 |
+
@st.cache_data
|
6 |
+
def show():
|
7 |
+
# Load data from Huggingface
|
8 |
+
dataset = load_dataset(
|
9 |
+
"krishaamer/taiwanese-college-students", data_files={'train': 'clean.csv'})
|
10 |
+
|
11 |
+
# Convert the loaded dataset to a pandas DataFrame
|
12 |
+
df = dataset['train'].to_pandas()
|
13 |
+
|
14 |
+
# Generate and display the university ranking table
|
15 |
+
generate_university_ranking_table(df)
|
16 |
+
|
17 |
+
|
18 |
+
@st.cache_data
|
19 |
+
def generate_university_ranking_table(df):
|
20 |
+
# Count the number of respondents for each university and sort them
|
21 |
+
university_counts = df["你/妳在哪所大學念書?"].value_counts(
|
22 |
+
).sort_values(ascending=False).reset_index()
|
23 |
+
university_counts.columns = ['University', 'Number of Respondents']
|
24 |
+
|
25 |
+
# Display the table in Streamlit
|
26 |
+
st.table(university_counts)
|