Skip to content

Instantly share code, notes, and snippets.

@sriengchhunchheang
Last active May 27, 2024 04:31
Show Gist options
  • Save sriengchhunchheang/9e47ce8b493619c111e4359628b59863 to your computer and use it in GitHub Desktop.
Save sriengchhunchheang/9e47ce8b493619c111e4359628b59863 to your computer and use it in GitHub Desktop.
import streamlit as st
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px
import plotly.graph_objs as go
from sklearn.ensemble import RandomForestClassifier
from sklearn.tree import DecisionTreeClassifier
# import data
@st.cache_data
def read_data():
url = 'https://docs.google.com/spreadsheets/d/1_kzF44rlmD9sut5R5yZp3IIK4j4PlVvTgVt-nw9gAEE/edit?usp=sharing'
df = pd.read_html(url, header=0)[0]
new_header = df.iloc[0] #grab the first row for the header
df = df[1:] #take the data less the header row
df.columns = new_header #set the header row as the df header
# df = df.drop(['Age_Range','Salary_Range'], axis=1)
return df
def filter_dataframe(df):
# Filter DataFrame to include only columns with no None values
df_filtered = df.dropna(axis=1, how='all')
return df_filtered
st.set_page_config(
page_title= "VAMStack Course",
layout="wide",
#page_icon=None
)
st.write("# Welcome to Employee Management Record")
st.write("#### Name: Chhun , student ID: XXXXXXXX")
st.write("### Data Visualisation")
data = read_data()
new_data = filter_dataframe(data)
col07, col08, col09 = st.columns([1,6,1])
with col07:
st.write("")
with col08:
st.write(new_data, use_container_width=True)
with col09:
st.write("")
col10, col11, col12 = st.columns([1,6,1])
with col10:
st.write("")
with col11:
columns = data.columns.tolist()
s = data['Gender'].str.strip().value_counts()
counts = go.Bar(x=s.index,y=s.values,showlegend = True)
layout = go.Layout(title = "Summary graph")
datas = [counts]
fig = go.Figure(data=datas,layout=layout)
st.plotly_chart(fig)
with col12:
st.write("")
# Adding a function for selecting the model
col07, col08, col09 = st.columns([1, 6, 1])
with col07:
st.write("")
with col08:
st.subheader("Select Model")
model_option = st.selectbox(
"Choose a model for analysis",
("Random Forest", "Decision Tree")
)
if model_option == "Random Forest":
model = RandomForestClassifier()
elif model_option == "Decision Tree":
model = DecisionTreeClassifier()
st.write(f"Selected Model: {model_option}")
with col09:
st.write("")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment