Spaces:
Sleeping
Sleeping
Add first interactive chart (#2)
Browse files- Add first interactive chart (5903be19536a1b1e8a2be6790691aa40d5659ca5)
app.py
CHANGED
|
@@ -9,65 +9,61 @@
|
|
| 9 |
import streamlit as st
|
| 10 |
import altair as alt
|
| 11 |
from vega_datasets import data
|
|
|
|
|
|
|
| 12 |
|
| 13 |
st.title('Final Project')
|
| 14 |
|
| 15 |
-
st.text("The URL for this app is: https://huggingface.co/spaces/
|
| 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 |
-
.encode(
|
| 55 |
-
x=
|
| 56 |
-
y=
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
tab1, tab2 = st.tabs(["Streamlit theme (default)", "Altair native theme"])
|
| 69 |
-
|
| 70 |
-
with tab1:
|
| 71 |
-
st.altair_chart(chart, theme="streamlit", use_container_width=True)
|
| 72 |
-
with tab2:
|
| 73 |
-
st.altair_chart(chart, theme=None, use_container_width=True)
|
|
|
|
| 9 |
import streamlit as st
|
| 10 |
import altair as alt
|
| 11 |
from vega_datasets import data
|
| 12 |
+
import pandas as pd
|
| 13 |
+
import ipywidgets as widgets
|
| 14 |
|
| 15 |
st.title('Final Project')
|
| 16 |
|
| 17 |
+
st.text("The URL for this app is: https://huggingface.co/spaces/445final/final2.moved")
|
| 18 |
+
|
| 19 |
+
df = pd.read_csv('State_Employee_Pay.csv')
|
| 20 |
+
|
| 21 |
+
df_copy = df.copy
|
| 22 |
+
df['Period Pay Rate'] = df['Period Pay Rate'].str.replace(",", "")
|
| 23 |
+
df['YTD Gross'] = df['YTD Gross'].str.replace(",", "")
|
| 24 |
+
df['Period Pay Rate'] = df['Period Pay Rate'].astype(int)
|
| 25 |
+
df['YTD Gross'] = df['YTD Gross'].astype(int)
|
| 26 |
+
df = df.dropna()
|
| 27 |
+
df = df[df['YTD Gross']!= 0]
|
| 28 |
+
df['Agency'] = df['Agency'].str.lower()
|
| 29 |
+
df['Agency Division'] = df['Agency Division'].str.lower()
|
| 30 |
+
df['Employee Name'] = df['Employee Name'].str.lower()
|
| 31 |
+
df['Position Title'] = df['Position Title'].str.lower()
|
| 32 |
+
|
| 33 |
+
df_c = df[df['Agency'] == 'corrections']
|
| 34 |
+
df_t = df[df['Agency'] == 'transportation']
|
| 35 |
+
|
| 36 |
+
df1 = df_c
|
| 37 |
+
|
| 38 |
+
#agency_division_list = df1['Agency Division'].value_counts().tolist()
|
| 39 |
+
agency_division_list = df1['Agency Division'].unique().tolist()
|
| 40 |
+
|
| 41 |
+
selected_division = st.selectbox('Agency Division:',
|
| 42 |
+
options=agency_division_list,
|
| 43 |
+
index=0)
|
| 44 |
+
|
| 45 |
+
# horizontal bar chart
|
| 46 |
+
|
| 47 |
+
def division_positions(selected_division):
|
| 48 |
+
df_db = df1[df1['Agency Division'] == selected_division]
|
| 49 |
+
|
| 50 |
+
bar_chart_data = df_db.groupby('Position Title').agg(
|
| 51 |
+
employeeCount=('Employee Name', 'count'),
|
| 52 |
+
meanYTDGross=('YTD Gross', 'mean')).reset_index()
|
| 53 |
+
|
| 54 |
+
bar_chart_data = bar_chart_data.sort_values('meanYTDGross', ascending=False)
|
| 55 |
+
|
| 56 |
+
chart_bar = alt.Chart(bar_chart_data).mark_bar().encode(
|
| 57 |
+
x=alt.X('employeeCount', title = '# of Employees'),
|
| 58 |
+
y=alt.Y('Position Title:O'),
|
| 59 |
+
tooltip=['Position Title', 'employeeCount', alt.Tooltip(
|
| 60 |
+
'meanYTDGross:Q', format='$,.0f', title='Avg YTD Gross')]
|
| 61 |
+
).properties(title=f'Employee Count by Position in: {selected_division} (Sorted by Avg YTD Gross)',
|
| 62 |
+
height=alt.Step(20)).interactive()
|
| 63 |
+
return chart_bar
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
if selected_division:
|
| 67 |
+
final_chart = division_positions(selected_division)
|
| 68 |
+
st.altair_chart(final_chart, use_container_width=True)
|
| 69 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|