Upload app.py
Browse files
app.py
CHANGED
|
@@ -174,8 +174,19 @@ def build_cleaned_from_indices(df: pd.DataFrame,
|
|
| 174 |
cleaned[c] = cleaned[c].apply(parse_rank).astype("Int64")
|
| 175 |
ordered = ["NAME", "ID"] + [c for c in cleaned.columns if c not in ("NAME", "ID")]
|
| 176 |
cleaned = cleaned[ordered]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
return cleaned
|
| 178 |
|
|
|
|
| 179 |
def max_rank_in(cleaned: pd.DataFrame) -> int:
|
| 180 |
wards = [w for w in cleaned.columns if w not in ("NAME", "ID")]
|
| 181 |
mr = 0
|
|
|
|
| 174 |
cleaned[c] = cleaned[c].apply(parse_rank).astype("Int64")
|
| 175 |
ordered = ["NAME", "ID"] + [c for c in cleaned.columns if c not in ("NAME", "ID")]
|
| 176 |
cleaned = cleaned[ordered]
|
| 177 |
+
|
| 178 |
+
# ✅ เพิ่มการ sort ตาม ID
|
| 179 |
+
try:
|
| 180 |
+
# ถ้า ID เป็นตัวเลข
|
| 181 |
+
cleaned = cleaned.sort_values(by="ID", key=lambda x: pd.to_numeric(x, errors="coerce"))
|
| 182 |
+
except Exception:
|
| 183 |
+
# ถ้า ID เป็น string ก็จะ sort แบบ lexicographic
|
| 184 |
+
cleaned = cleaned.sort_values(by="ID")
|
| 185 |
+
|
| 186 |
+
cleaned = cleaned.reset_index(drop=True)
|
| 187 |
return cleaned
|
| 188 |
|
| 189 |
+
|
| 190 |
def max_rank_in(cleaned: pd.DataFrame) -> int:
|
| 191 |
wards = [w for w in cleaned.columns if w not in ("NAME", "ID")]
|
| 192 |
mr = 0
|