The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Visualize expenses by category from bank CSVs

To visualize expenses by category from bank CSVs, follow these steps:


1. Prepare the CSV File

Ensure your CSV file has columns like:

  • Date

  • Description

  • Amount (negative for expenses, positive for income)

  • Category (optional – you can manually or programmatically assign these)


2. Load and Clean Data (Python Example)

python
import pandas as pd # Load CSV df = pd.read_csv('bank_statement.csv') # Optional: Convert date df['Date'] = pd.to_datetime(df['Date']) # Ensure 'Amount' is numeric df['Amount'] = pd.to_numeric(df['Amount'], errors='coerce') # Filter only expenses (negative amounts) expenses = df[df['Amount'] < 0]

3. Categorize Transactions (If Needed)

If no Category column exists:

python
def categorize(description): if 'grocery' in description.lower(): return 'Groceries' elif 'uber' in description.lower(): return 'Transport' elif 'netflix' in description.lower(): return 'Entertainment' else: return 'Other' expenses['Category'] = expenses['Description'].apply(categorize)

4. Group and Summarize Expenses

python
category_summary = expenses.groupby('Category')['Amount'].sum().abs().sort_values(ascending=False) print(category_summary)

5. Visualize with Pie or Bar Chart

python
import matplotlib.pyplot as plt # Pie Chart category_summary.plot(kind='pie', autopct='%1.1f%%', figsize=(8, 8), title='Expenses by Category') plt.ylabel('') plt.tight_layout() plt.show() # Or Bar Chart category_summary.plot(kind='bar', figsize=(10, 6), title='Expenses by Category') plt.xlabel('Category') plt.ylabel('Total Spent') plt.tight_layout() plt.show()

Optional: Interactive Visualization

For more interactive visuals, consider using Plotly:

python
import plotly.express as px fig = px.pie(values=category_summary.values, names=category_summary.index, title='Expenses by Category') fig.show()

Would you like to upload a CSV so I can generate the chart for you?

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About