This guide is designed to help business students leverage the latest artificial intelligence technologies to achieve what used to be not within their reach. Students will realize that AI is not just a minor improvement in efficiency, but is a tool that make the impossible possible.
These labs require a basic Python environment with NumPy and Matplotlib installed. The “Antigravity Agent Prompt” is the instruction a student would give the Antigravity system after the initial code is written and executed.
Lab 1: Financial Time Series Styling (Line Chart)
Concept: Introduction to basic data visualization and the use of the AI agent to apply complex, specific style modifications (like the Financial Times aesthetic) that a beginner wouldn’t know how to code manually. Various chart styles are available on moretheme package as well.
Initial Python Code: This code generates a simple line chart simulating daily stock prices.
Code
import matplotlib.pyplot as pltimport numpy as np# Sample data for 30 daysdays = np.arange(1, 31)# Simple simulated price trend with some volatilityprices =100+ days *0.5+ np.random.normal(0, 5, len(days))# Basic Line Plotplt.figure(figsize=(7, 6))plt.plot(days, prices, color='blue', linewidth=2)plt.title('Simulated Stock Price Over 30 Days')plt.xlabel('Day')plt.ylabel('Price ($)')plt.grid(True, linestyle='--', alpha=0.6)plt.show()
“Convert the entire visualization style of the plotted stock price data to adhere to the visual guidelines of the Financial Times (FT). The changes should include the signature salmon-pink background, dark text, clean axis lines, and a minimalist grid.”
Lab 2: Simple Profit & Loss Calculation and Output
Concept: Introduction to Python variables, basic arithmetic operations, and formatted output for financial reporting.
Initial Python Code: This code calculates basic profit/loss for a business.
Code
# Variables for a simple business quarterrevenue =50000.00cogs =25000.00# Cost of Goods Soldoperating_expenses =15000.00# Calculationgross_profit = revenue - cogsnet_profit = gross_profit - operating_expenses# Basic Outputprint("--- Q1 Financial Summary ---")print("Revenue: $", revenue)print("Gross Profit: $", gross_profit)print("Net Profit: $", net_profit)
“Refactor the output to use an f-string for better readability. Ensure all currency values are formatted to two decimal places and include a comma as a thousands separator.”
Concept: Introduction to Pandas (a crucial data analysis library), basic data loading from a dictionary, and conditional filtering—a fundamental business intelligence task.
Initial Python Code: This code uses a dictionary to store customer data and prints all records.
Code
import pandas as pd# Sample Customer Datadata = {'Customer_ID': [101, 102, 103, 104, 105],'Annual_Spend': [1500, 350, 7800, 4500, 900],'Region': ['North', 'South', 'North', 'West', 'East']}df = pd.DataFrame(data)# Print the entire DataFrameprint("--- All Customer Data ---")print(df)
--- All Customer Data ---
Customer_ID Annual_Spend Region
0 101 1500 North
1 102 350 South
2 103 7800 North
3 104 4500 West
4 105 900 East
Antigravity Agent Prompt:
“Modify the code to create a new DataFrame called high_value_customers that only includes customers with an Annual_Spend greater than or equal to $4,000. Then, sort this new filtered DataFrame in descending order by Annual_Spend before printing it.”
--- All Customer Data ---
Customer_ID Annual_Spend Region
0 101 1500 North
1 102 350 South
2 103 7800 North
3 104 4500 West
4 105 900 East
--- High Value Customers ---
Customer_ID Annual_Spend Region
2 103 7800 North
3 104 4500 West
Lab 4: Simple Break-Even Analysis
Concept: Applying a basic business formula (Break-Even Point = Fixed Costs / (Selling Price - Variable Cost)) and using Python to calculate the result.
Initial Python Code: This code defines the variables but requires the AI to complete the calculation based on the formula.
Code
# Break-Even Analysis Variablesfixed_costs =10000.00selling_price_per_unit =50.00variable_cost_per_unit =30.00# To be calculated: Break-Even Point in Units# Formula: Fixed Costs / (Selling Price - Variable Cost)# print("Break-Even Point in Units: [YOUR ANSWER HERE]")
Antigravity Agent Prompt:
“Complete the code by calculating the Break-Even Point in Units using the provided formula. Store the result in a variable named break_even_units and print the final value with a clear descriptive label. Round the final result to the nearest whole number.”
Break-Even Point in Units: 500
Lab 5: Bar Chart for Regional Sales Comparison
Concept: Creating a bar chart to visualize categorical data, which is essential for sales and regional performance reporting.
Initial Python Code: This code sets up the data but only prints it.
Code
import matplotlib.pyplot as plt# Regional Sales Data (in thousands of dollars)regions = ['North', 'South', 'East', 'West']sales = [450, 280, 510, 390]# Initial Data Printprint("Regional Sales Data (in $K):")for r, s inzip(regions, sales):print(f"- {r}: ${s}K")# plt.bar(regions, sales) # Line to be uncommented or completed# plt.show()
Regional Sales Data (in $K):
- North: $450K
- South: $280K
- East: $510K
- West: $390K
Antigravity Agent Prompt:
“Complete the visualization: Use the Matplotlib plt.bar() function to create a bar chart of the regional sales data. Add a title ‘Quarterly Sales by Region’ and label the y-axis as ‘Sales (in $K)’. Finally, change the color of the bar representing the highest sales region to green to highlight performance.”
Lab 6: Basic Portfolio Risk and Return
Concept: Calculating the correlation and standard deviation (risk) of multiple simulated stock assets—a fundamental concept in finance.
Initial Python Code: This code simulates daily returns for two stocks and calculates their daily volatility.
“Using the df DataFrame, calculate the annualized volatility for both Stock_A and Stock_B (assuming 252 trading days). Then, calculate the correlation matrix between the two stocks. Finally, display both the annualized volatility and the correlation matrix, with the volatility formatted as a percentage.”
Lab 7: Advanced Data Cleaning and Handling Missing Values
Concept: Introduction to real-world data issues, specifically missing data imputation. Students must use Antigravity to intelligently fill in null values in a sales dataset.
Initial Python Code: This code creates a DataFrame with intentional missing values (NaN).
Code
import pandas as pdimport numpy as npdata = {'Transaction_ID': range(101, 111),'Sales_Amount': [150.0, 200.0, np.nan, 350.0, 100.0, 500.0, np.nan, 250.0, 400.0, 180.0],'Region': ['East', 'West', 'East', 'North', 'South', 'West', 'North', 'East', 'South', 'West']}df = pd.DataFrame(data)# Show initial state and null countsprint("Initial Data Info:")print(df.isnull().sum())print("\nDataFrame Head:")print(df.head())
Initial Data Info:
Transaction_ID 0
Sales_Amount 2
Region 0
dtype: int64
DataFrame Head:
Transaction_ID Sales_Amount Region
0 101 150.0 East
1 102 200.0 West
2 103 NaN East
3 104 350.0 North
4 105 100.0 South
Antigravity Agent Prompt:
“In the df DataFrame, fill the missing values (NaN) in the Sales_Amount column. Use the mean imputation strategy, but apply it group-by-group based on the Region column to ensure regional sales averages are respected. Print the updated DataFrame and confirm there are no remaining missing values.”
Initial Missing Values:
Transaction_ID 0
Sales_Amount 2
Region 0
dtype: int64
--- Updated DataFrame (After Imputation) ---
Transaction_ID Sales_Amount Region
0 101 150.0 East
1 102 200.0 West
2 103 200.0 East
3 104 350.0 North
4 105 100.0 South
5 106 500.0 West
6 107 350.0 North
7 108 250.0 East
8 109 400.0 South
9 110 180.0 West
--- Remaining Missing Values ---
Transaction_ID 0
Sales_Amount 0
Region 0
dtype: int64
Lab 8: Cohort Analysis with Date Manipulation
Concept: Calculating customer lifetime value metrics by grouping customers based on their acquisition time (Cohort Analysis). This requires advanced date and time indexing.
Initial Python Code: This code sets up a sample of customer order data with purchase dates.
Code
import pandas as pddata = {'Customer_ID': [1, 2, 1, 3, 2, 4, 3, 1, 5],'Order_Date': ['2023-01-15', '2023-02-01', '2023-03-20', '2023-01-25', '2023-04-10', '2023-02-15', '2023-04-05', '2023-05-01', '2023-03-05'],'Revenue': [50, 75, 40, 90, 60, 120, 30, 80, 150]}df = pd.DataFrame(data)df['Order_Date'] = pd.to_datetime(df['Order_Date'])# Find the first purchase date for each customer (Acquisition Date)acquisition_date = df.groupby('Customer_ID')['Order_Date'].min().reset_index()acquisition_date.columns = ['Customer_ID', 'Acquisition_Date']df = pd.merge(df, acquisition_date, on='Customer_ID')print("DataFrame with Acquisition Dates:")print(df.sort_values(by=['Customer_ID', 'Order_Date']))
“Using the existing df DataFrame, create a new column called Cohort_Month by extracting the year and month from the Acquisition_Date. Then, calculate a new column called Days_Since_Acquisition for each order. Finally, create a pivot table that shows the Total Revenue grouped by Cohort_Month, demonstrating a simple Cohort analysis.”
Concept: Preparing transactional data for association rule mining (Market Basket Analysis), which requires converting item lists into a binary matrix using One-Hot Encoding.
Initial Python Code: This code sets up a dictionary of transactions with multiple items per transaction.
“Convert the Items column in the df DataFrame from lists of products into a new DataFrame of binary (0 or 1) indicators for each unique product (i.e., One-Hot Encoding). The columns should represent the unique items: ‘Milk’, ‘Bread’, ‘Coffee’, ‘Sugar’, and ‘Butter’. The output should be a DataFrame where a ‘1’ indicates the item was present in the transaction. Do not include the Transaction_ID column in the final encoded result.”
Lab 10: Multi-Plot Visualization for KPI Reporting
Concept: Creating a multi-plot visualization (a 2x1 subplot layout) to display two related Key Performance Indicators (KPIs) side-by-side, a standard practice in business dashboards.
Initial Python Code: This code generates data for two KPIs: Monthly Revenue and Customer Churn Rate.
Code
import matplotlib.pyplot as pltimport pandas as pdimport numpy as np# Sample Data for 12 monthsmonths =range(1, 13)revenue =1000+ np.cumsum(np.random.normal(0, 150, 12))churn_rate =0.05+ np.random.normal(0, 0.015, 12)churn_rate[churn_rate <0] =0.01# Ensure no negative rates# Prepare a single figureplt.figure(figsize=(12, 6))# Plot only Revenue on the first subplotplt.subplot(1, 2, 1) # Define first plot areaplt.plot(months, revenue, marker='o', color='green')plt.title('Monthly Revenue')plt.xlabel('Month')plt.ylabel('Revenue ($)')plt.grid(True, axis='y', alpha=0.5)# plt.subplot(1, 2, 2) # Second subplot to be completed by Antigravity# plt.show()
Antigravity Agent Prompt:
“Complete the visualization: Define the second subplot in a 1 row, 2 column layout. On this second subplot, plot the churn_rate data using a red line. Title this plot ‘Monthly Churn Rate’ and format the y-axis ticks to display as percentages (e.g., 5.0%). Add an appropriate x-axis label. Ensure the entire figure is shown after the second plot is completed.”