Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -72,44 +72,40 @@ def display_tiles(df, cols):
|
|
| 72 |
|
| 73 |
# Function to detect the format and standardize the data
|
| 74 |
def standardize_data(df):
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
# Standardize column names to a common format
|
| 82 |
df = df.rename(columns={
|
| 83 |
'Issued Date': 'Issued Date',
|
| 84 |
'Expiry Date': 'Expiry Date',
|
| 85 |
'Cert. No': 'Cert No',
|
| 86 |
-
'Company Name': 'Name',
|
| 87 |
'Address': 'Address',
|
| 88 |
-
'Region': '
|
| 89 |
-
'Factory Type': '
|
| 90 |
'Contact': 'Contact',
|
| 91 |
-
'Phone': '
|
| 92 |
'E-mail': 'E-mail',
|
| 93 |
'Status': 'Status',
|
| 94 |
'Member Since': 'Member Since'
|
| 95 |
})
|
| 96 |
-
|
| 97 |
-
elif
|
| 98 |
-
required_columns = [
|
| 99 |
-
'Name', 'Address', 'Tel', 'Cuisine', 'Expiry DateDD/MM/YY', 'Location', 'Restaurant Type', 'Website', 'Directions'
|
| 100 |
-
]
|
| 101 |
-
# Standardize column names to a common format
|
| 102 |
df = df.rename(columns={
|
| 103 |
-
'Name': 'Name',
|
| 104 |
'Address': 'Address',
|
| 105 |
-
'Tel': '
|
| 106 |
-
'Cuisine': '
|
| 107 |
'Expiry DateDD/MM/YY': 'Expiry Date',
|
| 108 |
-
'Location': '
|
| 109 |
-
'Restaurant Type': '
|
| 110 |
'Website': 'Website',
|
| 111 |
'Directions': 'Directions'
|
| 112 |
})
|
|
|
|
| 113 |
else:
|
| 114 |
st.error("Unsupported file format")
|
| 115 |
return None, []
|
|
@@ -230,10 +226,10 @@ else:
|
|
| 230 |
company_name_filter = st.text_input("Company Name contains")
|
| 231 |
with col2:
|
| 232 |
# Filter by Location
|
| 233 |
-
location_filter = st.multiselect("Location", df['
|
| 234 |
with col3:
|
| 235 |
# Filter by Restaurant Type
|
| 236 |
-
restaurant_type_filter = st.multiselect("
|
| 237 |
with col4:
|
| 238 |
# Filter by Expiry Date
|
| 239 |
expiry_date_filter = st.date_input("Expiry Date", [])
|
|
@@ -242,11 +238,11 @@ else:
|
|
| 242 |
filtered_df = df.copy()
|
| 243 |
|
| 244 |
if company_name_filter:
|
| 245 |
-
filtered_df = filtered_df[filtered_df['Name'].str.contains(company_name_filter, case=False, na=False)]
|
| 246 |
if location_filter:
|
| 247 |
-
filtered_df = filtered_df[filtered_df['
|
| 248 |
if restaurant_type_filter:
|
| 249 |
-
filtered_df = filtered_df[filtered_df['
|
| 250 |
if expiry_date_filter:
|
| 251 |
if len(expiry_date_filter) == 1:
|
| 252 |
filtered_df = filtered_df[filtered_df['Expiry Date'] == expiry_date_filter[0]]
|
|
|
|
| 72 |
|
| 73 |
# Function to detect the format and standardize the data
|
| 74 |
def standardize_data(df):
|
| 75 |
+
format_1_columns = {'Issued Date', 'Expiry Date', 'Cert. No', 'Company Name', 'Address', 'Region',
|
| 76 |
+
'Factory Type', 'Contact', 'Phone', 'E-mail', 'Status', 'Member Since'}
|
| 77 |
+
format_2_columns = {'Name', 'Address', 'Tel', 'Cuisine', 'Expiry DateDD/MM/YY', 'Location', 'Restaurant Type',
|
| 78 |
+
'Website', 'Directions'}
|
| 79 |
+
|
| 80 |
+
if format_1_columns.issubset(df.columns):
|
|
|
|
| 81 |
df = df.rename(columns={
|
| 82 |
'Issued Date': 'Issued Date',
|
| 83 |
'Expiry Date': 'Expiry Date',
|
| 84 |
'Cert. No': 'Cert No',
|
| 85 |
+
'Company Name': 'Company Name',
|
| 86 |
'Address': 'Address',
|
| 87 |
+
'Region': 'Region',
|
| 88 |
+
'Factory Type': 'Factory Type',
|
| 89 |
'Contact': 'Contact',
|
| 90 |
+
'Phone': 'Phone',
|
| 91 |
'E-mail': 'E-mail',
|
| 92 |
'Status': 'Status',
|
| 93 |
'Member Since': 'Member Since'
|
| 94 |
})
|
| 95 |
+
required_columns = list(format_1_columns)
|
| 96 |
+
elif format_2_columns.issubset(df.columns):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
df = df.rename(columns={
|
| 98 |
+
'Name': 'Company Name',
|
| 99 |
'Address': 'Address',
|
| 100 |
+
'Tel': 'Phone',
|
| 101 |
+
'Cuisine': 'Factory Type',
|
| 102 |
'Expiry DateDD/MM/YY': 'Expiry Date',
|
| 103 |
+
'Location': 'Region',
|
| 104 |
+
'Restaurant Type': 'Factory Type',
|
| 105 |
'Website': 'Website',
|
| 106 |
'Directions': 'Directions'
|
| 107 |
})
|
| 108 |
+
required_columns = list(format_1_columns) # Use the same required columns for consistency
|
| 109 |
else:
|
| 110 |
st.error("Unsupported file format")
|
| 111 |
return None, []
|
|
|
|
| 226 |
company_name_filter = st.text_input("Company Name contains")
|
| 227 |
with col2:
|
| 228 |
# Filter by Location
|
| 229 |
+
location_filter = st.multiselect("Location", df['Region'].drop_duplicates())
|
| 230 |
with col3:
|
| 231 |
# Filter by Restaurant Type
|
| 232 |
+
restaurant_type_filter = st.multiselect("Factory Type", df['Factory Type'].drop_duplicates())
|
| 233 |
with col4:
|
| 234 |
# Filter by Expiry Date
|
| 235 |
expiry_date_filter = st.date_input("Expiry Date", [])
|
|
|
|
| 238 |
filtered_df = df.copy()
|
| 239 |
|
| 240 |
if company_name_filter:
|
| 241 |
+
filtered_df = filtered_df[filtered_df['Company Name'].str.contains(company_name_filter, case=False, na=False)]
|
| 242 |
if location_filter:
|
| 243 |
+
filtered_df = filtered_df[filtered_df['Region'].isin(location_filter)]
|
| 244 |
if restaurant_type_filter:
|
| 245 |
+
filtered_df = filtered_df[filtered_df['Factory Type'].isin(restaurant_type_filter)]
|
| 246 |
if expiry_date_filter:
|
| 247 |
if len(expiry_date_filter) == 1:
|
| 248 |
filtered_df = filtered_df[filtered_df['Expiry Date'] == expiry_date_filter[0]]
|