Spaces:
Sleeping
Sleeping
File size: 770 Bytes
1309ee8 aa74cd7 1309ee8 aa74cd7 1309ee8 aa74cd7 1309ee8 aa74cd7 1309ee8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import pandas as pd
CATEGORIES = {
"DINING": ["RESTAURANT", "CAFE", "FOOD TRUCK", "STARBUCKS"],
"TRANSPORT": ["UBER", "LYFT", "TAXI", "PETROL"],
"SHOPPING": ["AMAZON", "WALMART", "TARGET"],
"UTILITIES": ["ELECTRIC", "WATER", "INTERNET", "PG&E"]
}
def categorize_expenses(file):
if isinstance(file, str):
# Example file path
df = pd.read_csv(file)
else:
# Uploaded file
df = pd.read_csv(file.name)
df['Category'] = "OTHER"
for idx, row in df.iterrows():
description = str(row['Description']).upper()
for cat, keywords in CATEGORIES.items():
if any(kw in description for kw in keywords):
df.at[idx, 'Category'] = cat
break
return df |