AI for Business Insights

Python Labs for Google Antigravity

Objective

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 plt
import numpy as np

# Sample data for 30 days
days = np.arange(1, 31)
# Simple simulated price trend with some volatility
prices = 100 + days * 0.5 + np.random.normal(0, 5, len(days))

# Basic Line Plot
plt.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()

References:

Boston Consulting Group. (2025). The future is (anything but) stable (2025 Global Payments Report). https://web-assets.bcg.com/25/91/2269153c468ca43684442f055cb0/2025-global-payments-report-sep-2025.pdf

Antigravity Agent Prompt:

“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 quarter
revenue = 50000.00
cogs = 25000.00  # Cost of Goods Sold
operating_expenses = 15000.00

# Calculation
gross_profit = revenue - cogs
net_profit = gross_profit - operating_expenses

# Basic Output
print("--- Q1 Financial Summary ---")
print("Revenue: $", revenue)
print("Gross Profit: $", gross_profit)
print("Net Profit: $", net_profit)
--- Q1 Financial Summary ---
Revenue: $ 50000.0
Gross Profit: $ 25000.0
Net Profit: $ 10000.0

Antigravity Agent Prompt:

“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.”

--- Q1 Financial Summary ---
Revenue: $50,000.00
Gross Profit: $25,000.00
Net Profit: $10,000.00

Lab 3: Data Filtering for High-Value Customers

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 Data
data = {
    '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 DataFrame
print("--- 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 Variables
fixed_costs = 10000.00
selling_price_per_unit = 50.00
variable_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 Print
print("Regional Sales Data (in $K):")
for r, s in zip(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.

Code
import pandas as pd
import numpy as np

# Simulate 252 trading days (approx. 1 year)
dates = pd.to_datetime(pd.date_range(start='2024-01-01', periods=252, freq='B'))
df = pd.DataFrame(index=dates)

# Simulated Daily Returns
np.random.seed(42)
df['Stock_A'] = np.random.normal(loc=0.0005, scale=0.01, size=252)
df['Stock_B'] = np.random.normal(loc=0.0008, scale=0.015, size=252)

# Calculate Daily Volatility (Standard Deviation)
vol_a = df['Stock_A'].std()
vol_b = df['Stock_B'].std()

print("Daily Volatility (Risk):")
print(f"Stock A: {vol_a:.4f}")
print(f"Stock B: {vol_b:.4f}")
Daily Volatility (Risk):
Stock A: 0.0097
Stock B: 0.0150

Antigravity Agent Prompt:

“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.”

--- Annualized Volatility ---
Stock A: 15.35%
Stock B: 23.87%

--- Correlation Matrix ---
          Stock_A   Stock_B
Stock_A  1.000000  0.022158
Stock_B  0.022158  1.000000

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 pd
import numpy as np

data = {
    '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 counts
print("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 pd

data = {
    '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']))
DataFrame with Acquisition Dates:
   Customer_ID Order_Date  Revenue Acquisition_Date
0            1 2023-01-15       50       2023-01-15
2            1 2023-03-20       40       2023-01-15
7            1 2023-05-01       80       2023-01-15
1            2 2023-02-01       75       2023-02-01
4            2 2023-04-10       60       2023-02-01
3            3 2023-01-25       90       2023-01-25
6            3 2023-04-05       30       2023-01-25
5            4 2023-02-15      120       2023-02-15
8            5 2023-03-05      150       2023-03-05

Antigravity Agent Prompt:

“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.”

DataFrame with Acquisition Dates:
   Customer_ID Order_Date  Revenue Acquisition_Date
0            1 2023-01-15       50       2023-01-15
2            1 2023-03-20       40       2023-01-15
7            1 2023-05-01       80       2023-01-15
1            2 2023-02-01       75       2023-02-01
4            2 2023-04-10       60       2023-02-01
3            3 2023-01-25       90       2023-01-25
6            3 2023-04-05       30       2023-01-25
5            4 2023-02-15      120       2023-02-15
8            5 2023-03-05      150       2023-03-05

--- Cohort Analysis: Total Revenue by Cohort ---
              Revenue
Cohort_Month         
2023-01           290
2023-02           255
2023-03           150

Lab 9: Market Basket Analysis Pre-processing (One-Hot Encoding)

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.

Code
import pandas as pd

# Sample Transaction Data
data = {
    'Transaction_ID': [1, 2, 3, 4, 5],
    'Items': [['Milk', 'Bread'], ['Coffee', 'Milk', 'Sugar'], ['Bread', 'Butter'], ['Coffee', 'Bread', 'Milk'], ['Sugar']]
}
df = pd.DataFrame(data)

print("Raw Transaction Data:")
print(df)
Raw Transaction Data:
   Transaction_ID                  Items
0               1          [Milk, Bread]
1               2  [Coffee, Milk, Sugar]
2               3        [Bread, Butter]
3               4  [Coffee, Bread, Milk]
4               5                [Sugar]

Antigravity Agent Prompt:

“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.”

Raw Transaction Data:
   Transaction_ID                  Items
0               1          [Milk, Bread]
1               2  [Coffee, Milk, Sugar]
2               3        [Bread, Butter]
3               4  [Coffee, Bread, Milk]
4               5                [Sugar]

--- One-Hot Encoded Data ---
   Bread  Butter  Coffee  Milk  Sugar
0      1       0       0     1      0
1      0       0       1     1      1
2      1       1       0     0      0
3      1       0       1     1      0
4      0       0       0     0      1

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 plt
import pandas as pd
import numpy as np

# Sample Data for 12 months
months = 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 figure
plt.figure(figsize=(12, 6))

# Plot only Revenue on the first subplot
plt.subplot(1, 2, 1) # Define first plot area
plt.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.”