Create tools_excel.py
Browse files- tools_excel.py +19 -0
tools_excel.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import re
|
3 |
+
|
4 |
+
def excel_answer(file_path, question):
|
5 |
+
df = pd.read_excel(file_path)
|
6 |
+
# Example: sum for food sales, or other logic based on question
|
7 |
+
if 'food' in question.lower():
|
8 |
+
# Try to find a column with 'food' or a category column
|
9 |
+
if 'Category' in df.columns and 'Sales' in df.columns:
|
10 |
+
total = df[df['Category'].str.lower() == 'food']['Sales'].sum()
|
11 |
+
return f"{total:.2f}"
|
12 |
+
# Fallback: sum last column
|
13 |
+
total = df.iloc[:, -1].sum()
|
14 |
+
return f"{total:.2f}"
|
15 |
+
# Add more logic for average, etc., if needed
|
16 |
+
# Fallback: sum last column
|
17 |
+
total = df.iloc[:, -1].sum()
|
18 |
+
return f"{total:.2f}"
|
19 |
+
|