import pandas as pd
import numpy as np
# Define channels with their multipliers, group, spending ranges, and tactics
channels = {
"Google Ads": {
"multiplier": 2.0,
"group": "Paid",
"spend_range": (5000, 12000),
"tactics": [
"Search Campaigns",
"Display Campaigns",
"Shopping Campaigns",
"Video Campaigns",
"App Campaigns",
"Remarketing Lists for Search Ads (RLSA)",
"Dynamic Search Ads (DSA)",
"Smart Campaigns",
"Performance Max Campaigns",
"Location Targeting",
"Keyword Expansion",
"A/B Testing Ad Copy",
"Audience Targeting",
],
},
"TV Ads": {
"multiplier": 1.5,
"group": "Paid",
"spend_range": (5000, 12000),
"tactics": [
"Linear TV",
"Connected TV (CTV)",
"Addressable TV",
"OTT Advertising",
"Sponsorships",
"Product Placement",
"Daytime Advertising",
"Prime Time Advertising",
"Local TV Advertising",
"National TV Advertising",
"Commercial Production",
],
},
"TikTok Ads": {
"multiplier": 1.8,
"group": "Paid",
"spend_range": (5000, 12000),
"tactics": [
"In-Feed Ads",
"Brand Takeover Ads",
"TopView Ads",
"Branded Hashtag Challenges",
"Branded Effects",
"Spark Ads",
"Collection Ads",
"Lead Generation Ads",
"TikTok Shopping Ads",
"Community Interaction",
"Influencer Marketing",
],
},
"Meta Ads": {
"multiplier": 1.6,
"group": "Paid",
"spend_range": (5000, 12000),
"tactics": [
"Image Ads",
"Video Ads",
"Carousel Ads",
"Collection Ads",
"Instant Experience Ads",
"Lead Generation Ads",
"Dynamic Ads",
"Stories Ads",
"Messenger Ads",
"Audience Targeting (Demographics, Interests, Behaviors)",
"Custom Audiences (Website Visitors, Email Lists)",
"Lookalike Audiences",
"Facebook Pixel Tracking",
],
},
"X Ads": {
"multiplier": 1.4,
"group": "Paid",
"spend_range": (5000, 12000),
"tactics": [
"Promoted Tweets",
"Promoted Accounts",
"Promoted Trends",
"Website Cards",
"App Cards",
"Direct Message Cards",
"Conversation Cards",
"Follower Ads",
"Twitter Takeover",
"Targeting by Keywords",
"Targeting by Interests",
"Targeting by Demographics",
],
},
"Instagram Ads": {
"multiplier": 1.7,
"group": "Paid",
"spend_range": (5000, 12000),
"tactics": [
"Image Ads",
"Video Ads",
"Carousel Ads",
"Stories Ads",
"Explore Ads",
"Shopping Ads",
"Reels Ads",
"Collection Ads",
"IGTV Ads",
"Branded Content Ads",
"Influencer Marketing",
"Targeting by Interests",
"Targeting by Demographics",
],
},
"YouTube Reels": {
"multiplier": 1.9,
"group": "Paid",
"spend_range": (5000, 12000),
"tactics": [
"In-Stream Ads",
"Bumper Ads",
"Discovery Ads",
"Overlay Ads",
"Sponsored Cards",
"Masthead Ads",
"Skippable Video Ads",
"Non-Skippable Video Ads",
"YouTube Shorts Ads",
"Targeting by Demographics",
"Targeting by Interests",
],
},
"Affiliate Marketing": {
"multiplier": 3.0,
"group": "Paid",
"spend_range": (5000, 12000),
"tactics": [
"Coupon Websites",
"Review Websites",
"Bloggers",
"Influencers",
"Email Marketing",
"Banner Ads",
"Contextual Advertising",
"Cost Per Sale (CPS)",
"Cost Per Lead (CPL)",
"Affiliate Networks",
],
},
"Email Marketing": {
"multiplier": 4.0,
"group": "Organic",
"spend_range": (2000, 6000),
"tactics": ["Newsletter", "Promotional Emails", "Transactional Emails"],
},
"SEO": {
"multiplier": 5.0,
"group": "Organic",
"spend_range": (2000, 6000),
"tactics": [
"Keyword Research",
"On-Page Optimization",
"Off-Page Optimization",
"Content Creation",
],
},
}
# Create a date range for 200 weeks
start_date = "2022-01-03" # starting on a Monday
weeks = pd.date_range(start=start_date, periods=200, freq="W-MON")
# Set a seed for reproducibility
np.random.seed(42)
# Prepare a list for spending data (one row per channel per week)
spending_rows = []
# For each week, generate spending for each channel.
# Use channel-specific spending ranges.
for date in weeks:
for channel, info in channels.items():
low, high = info["spend_range"]
# With 80% probability, generate a spend; otherwise 0.
if np.random.rand() < 0.8:
spend = np.random.uniform(low, high)
else:
spend = 0.0
# Choose a random tactic for paid channels
if info["group"] == "Paid":
tactic = np.random.choice(info["tactics"])
else:
tactic = None # or "N/A" for organic if you prefer
spending_rows.append(
{
"date": date.strftime("%Y-%m-%d"),
"channel": channel,
"channel_group": info["group"],
"channel_level_tactic": tactic,
"geo": "US",
"spend": round(spend, 2),
}
)
# Create the spending DataFrame
spend_df = pd.DataFrame(spending_rows)
# Now, generate the revenue data.
# For each week, revenue = baseline + sum(spend * multiplier) + noise
baseline = 100000 # baseline revenue per week
revenue_rows = []
# Group spending data by week (date)
for date, group in spend_df.groupby("date"):
contribution = 0
for _, row in group.iterrows():
channel = row["channel"]
spend = row["spend"]
multiplier = channels[channel]["multiplier"]
contribution += spend * multiplier
# Add a baseline and a small noise (±2000)
noise = np.random.uniform(-2000, 2000)
revenue = baseline + contribution + noise
revenue_rows.append({"date": date, "geo": "US", "revenue": round(revenue, 2)})
# Create the revenue DataFrame
revenue_df = pd.DataFrame(revenue_rows)
revenue_df = revenue_df[revenue_df["date"] < "2025-04-11"]
spend_df = spend_df[spend_df["date"] < "2025-04-11"]
# Save the dataframes to CSV files
spend_df.to_csv("spending_data.csv", index=False)
revenue_df.to_csv("revenue_data.csv", index=False)
print("Spending data shape:", spend_df.shape)
print("Revenue data shape:", revenue_df.shape)
print("Files generated: spending_data.csv, revenue_data.csv")