Repository navigation
Expand file tree
/
Copy pathplot.py
More file actions
37 lines (28 loc) · 1.38 KB
/
Copy pathplot.py
File metadata and controls
37 lines (28 loc) · 1.38 KB
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
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
# Load dataset
df = pd.read_pickle("./data/final_dataset.pkl")
st.write("##### 📌 Track the Popularity of a Recipe Over Time, based on best_score values #####")
# Extract unique recipe names
unique_recipe_names = df['recipe_name'].unique()
# Sidebar to select sample questions
selected_dish = st.selectbox("##### ❓ Select a recipe to analyze:", options=unique_recipe_names)
if st.button("Analyze"):
with st.spinner("Generating response..."):
# Filter rows
recipe_df = df[df['recipe_name'] == selected_dish][['created_at', 'best_score']]
# Convert created_at to datetime if it's not already
recipe_df['created_at'] = pd.to_datetime(recipe_df['created_at'], unit='s')
# Set created_at as the index
recipe_df.set_index('created_at', inplace=True)
# Plotting
st.set_option('deprecation.showPyplotGlobalUse', False)
plt.figure(figsize=(10, 6))
recipe_df.plot(color='skyblue')
plt.xlabel('Time')
plt.ylabel('Best Score')
plt.title(f'{selected_dish} Recipe Ratings Over Time') # Dynamic title based on selected recipe
plt.xticks(rotation=45) # Rotate x-axis labels for better readability
plt.tight_layout() # Adjust layout to prevent clipping of labels
st.pyplot() # Display the plot in Streamlit