Briemcc commited on
Commit
5903be1
·
verified ·
1 Parent(s): f3aef47

Add first interactive chart

Browse files
Files changed (1) hide show
  1. app.py +55 -59
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/jnaiman/is445_demo")
16
-
17
- source = data.seattle_weather()
18
-
19
- scale = alt.Scale(
20
- domain=["sun", "fog", "drizzle", "rain", "snow"],
21
- range=["#e7ba52", "#a7a7a7", "#aec7e8", "#1f77b4", "#9467bd"],
22
- )
23
- color = alt.Color("weather:N", scale=scale)
24
-
25
- # We create two selections:
26
- # - a brush that is active on the top panel
27
- # - a multi-click that is active on the bottom panel
28
- brush = alt.selection_interval(encodings=["x"])
29
- click = alt.selection_point(encodings=["color"])
30
-
31
- # Top panel is scatter plot of temperature vs time
32
- points = (
33
- alt.Chart()
34
- .mark_point()
35
- .encode(
36
- alt.X("monthdate(date):T", title="Date"),
37
- alt.Y(
38
- "temp_max:Q",
39
- title="Maximum Daily Temperature (C)",
40
- scale=alt.Scale(domain=[-5, 40]),
41
- ),
42
- color=alt.condition(brush, color, alt.value("lightgray")),
43
- size=alt.Size("precipitation:Q", scale=alt.Scale(range=[5, 200])),
44
- )
45
- .properties(width=550, height=300)
46
- .add_params(brush)
47
- .transform_filter(click)
48
- )
49
-
50
- # Bottom panel is a bar chart of weather type
51
- bars = (
52
- alt.Chart()
53
- .mark_bar()
54
- .encode(
55
- x="count()",
56
- y="weather:N",
57
- color=alt.condition(click, color, alt.value("lightgray")),
58
- )
59
- .transform_filter(brush)
60
- .properties(
61
- width=550,
62
- )
63
- .add_params(click)
64
- )
65
-
66
- chart = alt.vconcat(points, bars, data=source, title="Seattle Weather: 2012-2015")
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
+