harrychangjr commited on
Commit
a8b63b9
1 Parent(s): 6e28e35

Update pages/content.py

Browse files
Files changed (1) hide show
  1. pages/content.py +71 -5
pages/content.py CHANGED
@@ -33,7 +33,7 @@ st.set_page_config(page_title="Content - Tiktok Analytics Dashboard", page_icon
33
  st.header("Content")
34
  st.markdown("""Upload your files here to load your data!
35
 
36
- *'Trending videos' (xlsx or csv format)*
37
  """)
38
 
39
  def plot_chart(data, chart_type, x_var, y_var, z_var=None, show_regression_line=False, show_r_squared=False):
@@ -153,6 +153,17 @@ if uploaded_files:
153
  AgGrid(data)
154
 
155
  data_list.append(data)
 
 
 
 
 
 
 
 
 
 
 
156
  #st.write(data_list)
157
 
158
  #tab1, tab2 = st.tabs(["Trending Videos", "Video Posts"])
@@ -180,10 +191,66 @@ if uploaded_files:
180
  data['Cleaned_title'] = data['Video title'].apply(clean_title)
181
  # Add a new column to store the hashtag count
182
  data['Hashtag_count'] = data['Hashtags'].apply(len)
 
 
 
 
 
 
183
  st.write(data)
184
- options = ["Total views", "Total shares", "Total likes", "Total comments", "Number of Hashtags", "Hashtag Performance"]
185
  selected_feature = st.selectbox(label="Select feature", options=options, index=0)
186
- if selected_feature == "Total views":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
  data = data.sort_values(by='Total views', ascending=True)
188
  fig = px.bar(data, x='Total views', y='Cleaned_title', title='Views of trending videos for the week',
189
  color_discrete_sequence=px.colors.qualitative.Alphabet, hover_data={'Total views': ':.2f'})
@@ -579,5 +646,4 @@ if uploaded_files:
579
 
580
  #with tab2:
581
  #if 'video_view_within_days' not in data.columns: #Video Posts
582
- #pass
583
-
 
33
  st.header("Content")
34
  st.markdown("""Upload your files here to load your data!
35
 
36
+ *'Trending videos', 'Video Posts' (xlsx or csv format)*
37
  """)
38
 
39
  def plot_chart(data, chart_type, x_var, y_var, z_var=None, show_regression_line=False, show_r_squared=False):
 
153
  AgGrid(data)
154
 
155
  data_list.append(data)
156
+ # get common columns
157
+ common_columns = set.intersection(*(set(data.columns) for data in data_list))
158
+
159
+ # keep only common columns
160
+ dataframes = [data[common_columns] for data in data_list]
161
+
162
+ # concatenate all dataframes
163
+ data = pd.concat(data_list)
164
+
165
+ # drop duplicates
166
+ data = data.drop_duplicates()
167
  #st.write(data_list)
168
 
169
  #tab1, tab2 = st.tabs(["Trending Videos", "Video Posts"])
 
191
  data['Cleaned_title'] = data['Video title'].apply(clean_title)
192
  # Add a new column to store the hashtag count
193
  data['Hashtag_count'] = data['Hashtags'].apply(len)
194
+ # Convert the 'post time' column to datetime format
195
+ data['Post time'] = pd.to_datetime(data['Post time'])
196
+ # Create new columns for 'weekday', 'hour' and 'minute'
197
+ data['weekday_posted'] = data['Post time'].dt.day_name()
198
+ data['hour_posted'] = data['Post time'].dt.hour
199
+ data['min_posted'] = data['Post time'].dt.minute
200
  st.write(data)
201
+ options = ["Summary", "Total views", "Total shares", "Total likes", "Total comments", "Number of Hashtags", "Hashtag Performance"]
202
  selected_feature = st.selectbox(label="Select feature", options=options, index=0)
203
+
204
+ if selected_feature == "Summary":
205
+ x_var = st.sidebar.selectbox("Select X variable", data.columns)
206
+ y_var = st.sidebar.selectbox("Select Y variable", data.columns)
207
+ show_regression_line = False
208
+
209
+ z_var_options = ["None"] + list(data.columns)
210
+ z_var = st.sidebar.selectbox("Select Z variable for 3D charts (if applicable)", z_var_options)
211
+
212
+
213
+ tab1, tab2, tab3, tab4, tab5, tab6, tab7 = st.tabs(["Line", "Bar", "Scatterplot", "Heatmap",
214
+ "3D Scatterplot", "3D Lineplot", "3D Surfaceplot"])
215
+ with tab1:
216
+ st.write("Lineplot")
217
+ plot_chart(data, "line", x_var, y_var)
218
+
219
+ with tab2:
220
+ st.write("Barplot")
221
+ plot_chart(data, "bar", x_var, y_var)
222
+
223
+ with tab3:
224
+ st.write("Scatterplot")
225
+ show_regression_line = st.checkbox("Show regression line for scatterplot")
226
+ plot_chart(data, "scatter", x_var, y_var, show_regression_line=show_regression_line)
227
+
228
+ with tab4:
229
+ st.write("Heatmap")
230
+ plot_chart(data, "heatmap", x_var, y_var)
231
+
232
+ with tab5:
233
+ st.write("3D Scatterplot")
234
+ if z_var != "None":
235
+ plot_chart(data, "scatter_3d", x_var, y_var, z_var)
236
+
237
+ with tab6:
238
+ st.write("3D Lineplot")
239
+ if z_var != "None":
240
+ plot_chart(data, "line_3d", x_var, y_var, z_var)
241
+
242
+ with tab7:
243
+ st.write("3D Surfaceplot")
244
+ if z_var != "None":
245
+ plot_chart(data, "surface_3d", x_var, y_var, z_var)
246
+
247
+ #with tab8:
248
+ #st.write("Radar chart for 'Last 60 days'")
249
+ #radar_columns = ['Video views', 'Profile views', 'Likes', 'Comments', 'Shares']
250
+ #plot_radar_chart(data, radar_columns)
251
+ # Add more conditions for other specific file names if needed
252
+
253
+ elif selected_feature == "Total views":
254
  data = data.sort_values(by='Total views', ascending=True)
255
  fig = px.bar(data, x='Total views', y='Cleaned_title', title='Views of trending videos for the week',
256
  color_discrete_sequence=px.colors.qualitative.Alphabet, hover_data={'Total views': ':.2f'})
 
646
 
647
  #with tab2:
648
  #if 'video_view_within_days' not in data.columns: #Video Posts
649
+ #pass