fschwartzer commited on
Commit
b6a54e8
1 Parent(s): 96a6d51

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import requests
3
  import pandas as pd
 
4
 
5
  def fetch_data_to_dataframe(query, limit=50):
6
  BASE_URL = "https://api.mercadolibre.com/sites/MLB/search"
@@ -14,8 +15,14 @@ def fetch_data_to_dataframe(query, limit=50):
14
  df = df[['title', 'price', 'currency_id', 'condition', 'permalink']]
15
  df.columns = ['Title', 'Price', 'Currency', 'Condition', 'Link']
16
 
17
- median_price = df['Price'].median()
18
- return median_price, df
 
 
 
 
 
 
19
  else:
20
  return 0, pd.DataFrame()
21
 
 
1
  import gradio as gr
2
  import requests
3
  import pandas as pd
4
+ from scipy import stats
5
 
6
  def fetch_data_to_dataframe(query, limit=50):
7
  BASE_URL = "https://api.mercadolibre.com/sites/MLB/search"
 
15
  df = df[['title', 'price', 'currency_id', 'condition', 'permalink']]
16
  df.columns = ['Title', 'Price', 'Currency', 'Condition', 'Link']
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].drop(columns=['z_score'])
23
+
24
+ median_price = df_filtered['Price'].median()
25
+ return median_price, df_filtered
26
  else:
27
  return 0, pd.DataFrame()
28