Download tools/excel_tool.py from LonghaoWang/Final_Assignment_Template: direct link, hf CLI and curl.
- Browser
- Download file 562 Bytes
-
https://huggingface.co/spaces/LonghaoWang/Final_Assignment_Template/resolve/main/tools/excel_tool.py
- Command line
-
hf download hf://spaces/LonghaoWang/Final_Assignment_Template/tools/excel_tool.py
-
curl -L -o excel_tool.py https://huggingface.co/spaces/LonghaoWang/Final_Assignment_Template/resolve/main/tools/excel_tool.py
562 Bytes
| """Excel sales aggregation.""" | |
| from __future__ import annotations | |
| from pathlib import Path | |
| from typing import Optional | |
| import pandas as pd | |
| DRINK_COLS = {"soda", "drink", "drinks", "beverage", "beverages", "coffee", "tea"} | |
| def total_food_sales_usd(path: Path) -> Optional[str]: | |
| df = pd.read_excel(path) | |
| numeric = df.select_dtypes(include="number") | |
| food_cols = [c for c in numeric.columns if str(c).strip().lower() not in DRINK_COLS] | |
| if not food_cols: | |
| return None | |
| total = float(df[food_cols].sum().sum()) | |
| return f"{total:.2f}" | |