Spaces:
Sleeping
Sleeping
fschwartzer
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -17,9 +17,17 @@ def fetch_data_to_dataframe(query, limit=50):
|
|
17 |
|
18 |
# Calculate z-scores of `df['Price']`
|
19 |
df['z_score'] = stats.zscore(df['Price'])
|
20 |
-
|
21 |
# Filter out rows where z-score is greater than 2
|
22 |
-
df_filtered = df[df['z_score'] <= 2]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
median_price = df_filtered['Price'].median()
|
25 |
return median_price, df_filtered
|
|
|
17 |
|
18 |
# Calculate z-scores of `df['Price']`
|
19 |
df['z_score'] = stats.zscore(df['Price'])
|
|
|
20 |
# Filter out rows where z-score is greater than 2
|
21 |
+
df_filtered = df[df['z_score'] <= 2]
|
22 |
+
|
23 |
+
# Further filter df_filtered to keep titles closely matching the query
|
24 |
+
# Split the query into keywords and check if each title contains them
|
25 |
+
keywords = query.lower().split()
|
26 |
+
# Assuming all keywords in the query must be present in the title for it to be considered relevant
|
27 |
+
for keyword in keywords:
|
28 |
+
df_filtered = df_filtered[df_filtered['Title'].str.lower().str.contains(keyword)]
|
29 |
+
|
30 |
+
df_filtered = df_filtered.drop(columns=['z_score'])
|
31 |
|
32 |
median_price = df_filtered['Price'].median()
|
33 |
return median_price, df_filtered
|