Spaces:
Sleeping
Sleeping
File size: 2,583 Bytes
3ddfd7a 5cad389 3ddfd7a 51d9500 3ddfd7a 5903be1 3ddfd7a 873a08b 3ddfd7a 5903be1 | 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 | # INSTRUCTIONS:
# 1. Open a "Terminal" by: View --> Terminal OR just the "Terminal" through the hamburger menu
# 2. run in terminal with: streamlit run app.py
# 3. click the "Open in Browser" link that pops up OR click on "Ports" and copy the URL
# 4. Open a Simple Browswer with View --> Command Palette --> Simple Browser: Show
# 5. use the URL from prior steps as intput into this simple browser
import streamlit as st
import altair as alt
from vega_datasets import data
import pandas as pd
import ipywidgets as widgets
st.title('Final Project')
st.text("The URL for this app is: https://huggingface.co/spaces/445final/final2.moved")
df = pd.read_csv('State_Employee_Pay.csv')
df_copy = df.copy
df['Period Pay Rate'] = df['Period Pay Rate'].str.replace(",", "")
df['YTD Gross'] = df['YTD Gross'].str.replace(",", "")
df['Period Pay Rate'] = df['Period Pay Rate'].astype(int)
df['YTD Gross'] = df['YTD Gross'].astype(int)
df = df.dropna()
df = df[df['YTD Gross']!= 0]
df['Agency'] = df['Agency'].str.lower()
df['Agency Division'] = df['Agency Division'].str.lower()
df['Employee Name'] = df['Employee Name'].str.lower()
df['Position Title'] = df['Position Title'].str.lower()
df_c = df[df['Agency'] == 'corrections']
df_t = df[df['Agency'] == 'transportation']
df1 = df_c
#agency_division_list = df1['Agency Division'].value_counts().tolist()
agency_division_list = df1['Agency Division'].unique().tolist()
selected_division = st.selectbox('Agency Division:',
options=agency_division_list,
index=0)
# horizontal bar chart
def division_positions(selected_division):
df_db = df1[df1['Agency Division'] == selected_division]
bar_chart_data = df_db.groupby('Position Title').agg(
employeeCount=('Employee Name', 'count'),
meanYTDGross=('YTD Gross', 'mean')).reset_index()
bar_chart_data = bar_chart_data.sort_values('meanYTDGross', ascending=False)
chart_bar = alt.Chart(bar_chart_data).mark_bar().encode(
x=alt.X('employeeCount', title = '# of Employees'),
y=alt.Y('Position Title:O'),
tooltip=['Position Title', 'employeeCount', alt.Tooltip(
'meanYTDGross:Q', format='$,.0f', title='Avg YTD Gross')]
).properties(title=f'Employee Count by Position in: {selected_division} (Sorted by Avg YTD Gross)',
height=alt.Step(20)).interactive()
return chart_bar
if selected_division:
final_chart = division_positions(selected_division)
st.altair_chart(final_chart, use_container_width=True)
|