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