Skip to content

Commit 5b67755

Browse files
Fix: Add get_data() to import CSV data easily
Co-authored-by: Garv Saini <garvkumarsaini@gmail.com>
1 parent 93c11c1 commit 5b67755

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

app.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
'Level 3': ['Task 1', 'Task 2', 'Task 3']
2121
}
2222

23+
#read in data
24+
@st.cache_data
25+
def get_data():
26+
df = pd.read_csv('./data/data.csv')
27+
return df
28+
2329
# Create the Streamlit web app
2430
def main():
2531
st.set_page_config(page_title="Zomato Data Analysis", page_icon="🥘", layout="wide")
@@ -37,7 +43,7 @@ def main():
3743
st.write('---')
3844

3945
st.markdown('- Load the dataset and identify the number of rows and columns.')
40-
df = pd.read_csv("./data/data.csv")
46+
df = get_data()
4147
st.write(df.head())
4248
st.write(f"Number of rows: {df.shape[0]}")
4349
st.write(f"Number of columns: {df.shape[1]}")
@@ -63,7 +69,7 @@ def main():
6369

6470
if selected_task == 'Task 2' and selected_level == 'Level 1':
6571
st.markdown('### Task 2: Descriptive Analysis')
66-
df = pd.read_csv("./data/data.csv")
72+
df = get_data()
6773
st.markdown('- Calculate basic statistical measures (mean, median, standard deviation, etc.) for numerical columns.')
6874
st.write(df.describe())
6975

@@ -95,7 +101,7 @@ def main():
95101
st.write('Top 10 Cities:', top_cities)
96102

97103
if selected_task == 'Task 3' and selected_level == 'Level 1':
98-
df = pd.read_csv("./data/data.csv")
104+
df = get_data()
99105
st.markdown("### Task 3: Geospatial Analysis")
100106

101107
st.markdown("- Visualize the locations of restaurants on a map using latitude and longitude information.")
@@ -123,7 +129,7 @@ def main():
123129
if selected_task == 'Task 1' and selected_level == 'Level 2':
124130
st.markdown("### Task 1: Table Booking and Online Delivery")
125131

126-
df = pd.read_csv("./data/data.csv")
132+
df = get_data()
127133

128134
st.markdown("- Determine the percentage of restaurants that offer table booking")
129135
table_booking_percentage = df['Has Table booking'].value_counts(normalize=True) * 100
@@ -184,7 +190,7 @@ def main():
184190
if selected_task == 'Task 2' and selected_level == 'Level 2':
185191
st.markdown("### Task 2: Price Range Analysis")
186192

187-
df = pd.read_csv("./data/data.csv")
193+
df = get_data()
188194

189195
st.markdown("- Determine the most common price range among all the restaurants")
190196
most_common_price_range = df['Price range'].mode()[0]
@@ -231,7 +237,7 @@ def main():
231237

232238
if selected_task == 'Task 3' and selected_level == 'Level 2':
233239
st.markdown("### Task 3: Feature Engineering")
234-
df2 = pd.read_csv("./data/data.csv")
240+
df2 = get_data()
235241
st.write('---')
236242

237243
st.markdown("- Extract additional features from the existing columns, such as the length of the restaurant name or address.")
@@ -284,7 +290,7 @@ def main():
284290
st.write('---')
285291

286292
if selected_task == 'Task 1' and selected_level == 'Level 3':
287-
df = pd.read_csv("./data/data.csv")
293+
df = get_data()
288294

289295
st.markdown("### Task 1: Predictive Modelling")
290296

@@ -350,7 +356,7 @@ def main():
350356
st.write('---')
351357

352358
if selected_task == 'Task 2' and selected_level == 'Level 3':
353-
df = pd.read_csv("./data/data.csv")
359+
df = get_data()
354360

355361
le = LabelEncoder()
356362
df['Cuisines'] = le.fit_transform(df['Cuisines'])
@@ -402,8 +408,7 @@ def main():
402408

403409

404410
if selected_task == 'Task 3' and selected_level == 'Level 3':
405-
st.write("Restaurant Ratings Analysis")
406-
df = pd.read_csv("./data/data.csv")
411+
df = get_data()
407412

408413
st.write("### Distribution of Aggregate Rating")
409414
st.plotly_chart(px.histogram(df, x='Aggregate rating', nbins=20, title='Distribution of Aggregate Rating'))

0 commit comments

Comments
 (0)