Spaces:
Sleeping
Sleeping
File size: 2,934 Bytes
fc7d0e7 2167a2b 6e83e2f aadb326 6e83e2f 0b58ed2 6e83e2f 872dd1d fc7d0e7 6e83e2f 9f7520d 6e83e2f 987c354 0783c6d fc7d0e7 aadb326 987c354 9f7520d 0b58ed2 |
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 |
import streamlit as st
import pandas as pd
@st.cache_data
def show(df):
st.title("Respondent Demographics")
st.markdown(
f"<h2 style='text-align: center;'>Study Level</h2>", unsafe_allow_html=True)
show_student_counts(df)
st.markdown(
f"<h2 style='text-align: center;'>Age Distribution</h2>", unsafe_allow_html=True)
show_student_age_ranking(df)
st.markdown(
f"<h2 style='text-align: center;'>University</h2>", unsafe_allow_html=True)
st.text("Universities with the most respondents are those where flyers were distributed.")
generate_university_ranking_table(df)
st.markdown(
f"<h2 style='text-align: center;'>Field of Study</h2>", unsafe_allow_html=True)
st.text("These fields of study have not been normalized.")
show_field_of_study_ranking(df)
st.markdown(
f"<h2 style='text-align: center;'>Personality Type</h2>", unsafe_allow_html=True)
show_mbti_ranking(df)
def generate_university_ranking_table(df):
# Count the number of respondents for each university and sort them
university_counts = df["你/妳在哪所大學念書?"].value_counts(
).sort_values(ascending=False).reset_index()
university_counts.columns = ['University', 'Number of Respondents']
# Display the table in Streamlit
st.table(university_counts)
def show_student_counts(df):
# Counting the number of undergraduate and graduate students in the field "你/妳的學習階段:"
student_counts = df['你/妳的學習階段:'].value_counts()
# Converting the Series to a DataFrame for better table formatting
student_counts_df = student_counts.reset_index()
student_counts_df.columns = ['Study Level', 'Number of Students']
# Display the DataFrame as a table in Streamlit
st.table(student_counts_df)
def show_mbti_ranking(df):
# Count the occurrences of each MBTI type and sort them
mbti_counts = df["你/妳的MBTI?(選填)"].value_counts(
).sort_values(ascending=False).reset_index()
mbti_counts.columns = ['MBTI Type', 'Number of Students']
# Display the DataFrame as a table in Streamlit
st.table(mbti_counts)
def show_field_of_study_ranking(df):
# Count the occurrences of each field of study and sort them
field_of_study_counts = df["你/妳的學習科系:"].value_counts(
).sort_values(ascending=False).reset_index()
field_of_study_counts.columns = ['Field of Study', 'Number of Students']
# Display the DataFrame as a table in Streamlit
st.table(field_of_study_counts)
def show_student_age_ranking(df):
# Count the occurrences of each age and sort them
age_counts = df["你/妳幾歲?"].value_counts(
).sort_values(ascending=False).reset_index()
age_counts.columns = ['Age', 'Number of Students']
# Display the DataFrame as a table in Streamlit
st.table(age_counts)
|