joycecast commited on
Commit
30f3a3c
·
verified ·
1 Parent(s): 541a2d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -20
app.py CHANGED
@@ -116,7 +116,8 @@ with tabs[0]:
116
 
117
  with tabs[1]:
118
  st.header("Upload CTN File for Last Mile Summary")
119
- ctn_files = st.file_uploader("Upload one or more Excel files with Last Mile Service", type=["xlsx"], key="ctn_upload", accept_multiple_files=True)
 
120
 
121
  if ctn_files:
122
  df_list = []
@@ -126,23 +127,18 @@ with tabs[1]:
126
 
127
  df_ctn = pd.concat(df_list, ignore_index=True)
128
 
129
- # Try to match the correct column
130
- last_mile_col = [col for col in df_ctn.columns if "last mile" in col.lower()][0]
131
-
132
- # Uploaded Preview: group by MAWB + Last Mile Service
133
- st.subheader("MAWB Last Mile Cartons Count")
134
- if 'MAWB' in df_ctn.columns:
135
- preview_grouped = df_ctn.groupby(['MAWB', last_mile_col]).size().reset_index(name='CTN Count')
136
- st.dataframe(preview_grouped, use_container_width=True)
137
-
138
- # Grouped Summary: for Last Mile Service == GOFO/USPS, grouped by MAWB + Channal_name
139
- st.subheader("GOFO/USPS Each Channel Cartons Summary")
140
- if 'Channal_name' in df_ctn.columns:
141
- df_channel = df_ctn[
142
- (df_ctn[last_mile_col].str.upper() == 'GOFO') |
143
- (df_ctn[last_mile_col].str.upper() == 'USPS')
144
- ]
145
- grouped = df_channel.groupby(['MAWB', 'Channal_name']).size().reset_index(name='CTN Count')
146
- st.dataframe(grouped, use_container_width=True)
147
  else:
148
- st.warning("Column 'Channal_name' not found in the uploaded file(s). Please ensure this column exists.")
 
116
 
117
  with tabs[1]:
118
  st.header("Upload CTN File for Last Mile Summary")
119
+ ctn_files = st.file_uploader("Upload one or more Excel files with Last Mile Service",
120
+ type=["xlsx"], key="ctn_upload", accept_multiple_files=True)
121
 
122
  if ctn_files:
123
  df_list = []
 
127
 
128
  df_ctn = pd.concat(df_list, ignore_index=True)
129
 
130
+ # Columns of interest
131
+ carton_col = "No. Large box"
132
+ last_mile_col = "Last mile service"
133
+
134
+ # Count unique cartons by last mile service
135
+ st.subheader("Unique Cartons by Last Mile Service")
136
+ if carton_col in df_ctn.columns and last_mile_col in df_ctn.columns:
137
+ unique_summary = (
138
+ df_ctn.groupby(last_mile_col)[carton_col]
139
+ .nunique()
140
+ .reset_index(name="Unique Carton Count")
141
+ )
142
+ st.dataframe(unique_summary, use_container_width=True)
 
 
 
 
 
143
  else:
144
+ st.warning(f"Columns '{carton_col}' or '{last_mile_col}' not found in uploaded file(s).")