CoolFace
Apppublic

Navya-Sree/Finance_toolkit

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
categorizer.py26 linesDownload Raw Back to root
1import pandas as pd2 3CATEGORIES = {4    "DINING": ["RESTAURANT", "CAFE", "FOOD TRUCK", "STARBUCKS"],5    "TRANSPORT": ["UBER", "LYFT", "TAXI", "PETROL"],6    "SHOPPING": ["AMAZON", "WALMART", "TARGET"],7    "UTILITIES": ["ELECTRIC", "WATER", "INTERNET", "PG&E"]8}9 10def categorize_expenses(file):11    if isinstance(file, str):12        # Example file path13        df = pd.read_csv(file)14    else:15        # Uploaded file16        df = pd.read_csv(file.name)17    18    df['Category'] = "OTHER"19    20    for idx, row in df.iterrows():21        description = str(row['Description']).upper()22        for cat, keywords in CATEGORIES.items():23            if any(kw in description for kw in keywords):24                df.at[idx, 'Category'] = cat25                break26    return df