Niharmahesh commited on
Commit
e7d846b
·
verified ·
1 Parent(s): 9d720c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -23
app.py CHANGED
@@ -73,6 +73,7 @@ def load_and_concat_data():
73
  filtered_df = filtered_df.drop_duplicates()
74
 
75
  return filtered_df
 
76
  @st.cache_data()
77
  def get_unique_values(df):
78
  return {
@@ -81,28 +82,38 @@ def get_unique_values(df):
81
  'job_types': df['job_type'].unique()
82
  }
83
 
 
 
 
 
84
 
 
 
 
 
 
 
85
 
86
- def main():
87
- st.title("Job Listings Dashboard")
88
-
89
- df = load_and_concat_data()
90
-
91
- if df.empty:
92
- st.error("No data available. Please check your dataset.")
93
- return
94
-
95
- # Sidebar for navigation
96
- st.sidebar.title("Navigation")
97
- page = st.sidebar.radio("Go to", ["Dashboard", "Data Explorer"])
98
-
99
- if page == "Dashboard":
100
- display_dashboard(df)
101
- elif page == "Data Explorer":
102
- display_data_explorer(df)
103
 
104
- def create_chart(data, _x, y, title, color_sequence):
105
- fig = px.bar(data, x=_x, y=y, title=title, color_discrete_sequence=color_sequence)
 
 
 
 
 
 
 
 
106
  fig.update_layout(plot_bgcolor='rgba(0,0,0,0)', paper_bgcolor='rgba(0,0,0,0)', font_color='#FFFFFF')
107
  return fig
108
 
@@ -124,10 +135,11 @@ def display_dashboard(df):
124
  fig = create_chart(top_companies, top_companies.index, top_companies.values, "Top 10 Companies", ['#4e79a7'])
125
  st.plotly_chart(fig, use_container_width=True)
126
 
127
- df_by_date = df.groupby('date_posted').size().reset_index(name='count')
128
- fig = px.line(df_by_date, x='date_posted', y='count', title="Job Postings Over Time", color_discrete_sequence=['#4e79a7'])
129
- fig.update_layout(plot_bgcolor='rgba(0,0,0,0)', paper_bgcolor='rgba(0,0,0,0)', font_color='#FFFFFF')
130
- st.plotly_chart(fig, use_container_width=True)
 
131
 
132
  col3, col4 = st.columns(2)
133
 
@@ -142,6 +154,12 @@ def display_dashboard(df):
142
  fig.update_layout(plot_bgcolor='rgba(0,0,0,0)', paper_bgcolor='rgba(0,0,0,0)', font_color='#FFFFFF')
143
  st.plotly_chart(fig, use_container_width=True)
144
 
 
 
 
 
 
 
145
  @st.cache_data
146
  def filter_dataframe(df, companies, locations, job_types):
147
  filtered_df = df
@@ -182,5 +200,23 @@ def display_data_explorer(df):
182
 
183
  st.write(filtered_df.to_html(escape=False, index=False), unsafe_allow_html=True)
184
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  if __name__ == "__main__":
186
  main()
 
73
  filtered_df = filtered_df.drop_duplicates()
74
 
75
  return filtered_df
76
+
77
  @st.cache_data()
78
  def get_unique_values(df):
79
  return {
 
82
  'job_types': df['job_type'].unique()
83
  }
84
 
85
+ def create_chart(data, _x, y, title, color_sequence):
86
+ fig = px.bar(data, x=_x, y=y, title=title, color_discrete_sequence=color_sequence)
87
+ fig.update_layout(plot_bgcolor='rgba(0,0,0,0)', paper_bgcolor='rgba(0,0,0,0)', font_color='#FFFFFF')
88
+ return fig
89
 
90
+ def expand_time_series(df, date_col, start_date, end_date):
91
+ full_range = pd.date_range(start=start_date, end=end_date, freq='W')
92
+ df.set_index(date_col, inplace=True)
93
+ expanded_df = df.reindex(full_range).reset_index()
94
+ expanded_df.columns = ['Week', 'Job Postings']
95
+ return expanded_df
96
 
97
+ def create_weekly_dashboard(df):
98
+ df['Week'] = df['date_posted'].dt.to_period('W').apply(lambda r: r.start_time)
99
+ weekly_data = df.groupby('Week').size().reset_index(name='Job Postings')
100
+
101
+ start_date = weekly_data['Week'].min()
102
+ end_date = weekly_data['Week'].max()
103
+
104
+ expanded_weekly_data = expand_time_series(weekly_data, 'Week', start_date, end_date)
105
+ return expanded_weekly_data
 
 
 
 
 
 
 
 
106
 
107
+ @st.cache_data
108
+ def get_location_data(df):
109
+ location_counts = df['location'].value_counts().reset_index()
110
+ location_counts.columns = ['location', 'count']
111
+ return location_counts
112
+
113
+ def create_heatmap(location_data):
114
+ fig = px.density_mapbox(location_data, lat='latitude', lon='longitude', z='count', radius=10,
115
+ center=dict(lat=37.0902, lon=-95.7129), zoom=3,
116
+ mapbox_style="carto-darkmatter", title="Job Postings Heatmap")
117
  fig.update_layout(plot_bgcolor='rgba(0,0,0,0)', paper_bgcolor='rgba(0,0,0,0)', font_color='#FFFFFF')
118
  return fig
119
 
 
135
  fig = create_chart(top_companies, top_companies.index, top_companies.values, "Top 10 Companies", ['#4e79a7'])
136
  st.plotly_chart(fig, use_container_width=True)
137
 
138
+ # Weekly Job Postings Chart
139
+ weekly_data = create_weekly_dashboard(df)
140
+ fig_weekly = px.line(weekly_data, x='Week', y='Job Postings', title="Weekly Job Postings", color_discrete_sequence=['#4e79a7'])
141
+ fig_weekly.update_layout(plot_bgcolor='rgba(0,0,0,0)', paper_bgcolor='rgba(0,0,0,0)', font_color='#FFFFFF')
142
+ st.plotly_chart(fig_weekly, use_container_width=True)
143
 
144
  col3, col4 = st.columns(2)
145
 
 
154
  fig.update_layout(plot_bgcolor='rgba(0,0,0,0)', paper_bgcolor='rgba(0,0,0,0)', font_color='#FFFFFF')
155
  st.plotly_chart(fig, use_container_width=True)
156
 
157
+ # Job Postings Heatmap
158
+ st.subheader("Job Postings Heatmap")
159
+ location_data = get_location_data(df)
160
+ fig_heatmap = create_heatmap(location_data)
161
+ st.plotly_chart(fig_heatmap, use_container_width=True)
162
+
163
  @st.cache_data
164
  def filter_dataframe(df, companies, locations, job_types):
165
  filtered_df = df
 
200
 
201
  st.write(filtered_df.to_html(escape=False, index=False), unsafe_allow_html=True)
202
 
203
+ def main():
204
+ st.title("Job Listings Dashboard")
205
+
206
+ df = load_and_concat_data()
207
+
208
+ if df.empty:
209
+ st.error("No data available. Please check your dataset.")
210
+ return
211
+
212
+ # Sidebar for navigation
213
+ st.sidebar.title("Navigation")
214
+ page = st.sidebar.radio("Go to", ["Dashboard", "Data Explorer"])
215
+
216
+ if page == "Dashboard":
217
+ display_dashboard(df)
218
+ elif page == "Data Explorer":
219
+ display_data_explorer(df)
220
+
221
  if __name__ == "__main__":
222
  main()