-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_sample_data.py
More file actions
65 lines (51 loc) · 2.08 KB
/
Copy pathcreate_sample_data.py
File metadata and controls
65 lines (51 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import pandas as pd
import numpy as np
from datetime import datetime, timedelta
import random
def generate_sample_data():
"""Generate sample sales data for testing"""
print("🔄 Generating sample sales data...")
# Set random seed for reproducibility
np.random.seed(42)
# Define categories and products
categories = {
'Electronics': ['Laptop', 'Phone', 'Tablet', 'Headphones', 'Charger'],
'Clothing': ['T-shirt', 'Jeans', 'Jacket', 'Shoes', 'Hat'],
'Furniture': ['Chair', 'Table', 'Desk', 'Sofa', 'Bookshelf'],
'Food': ['Coffee', 'Snack', 'Drink', 'Candy', 'Biscuit']
}
regions = ['North', 'South', 'East', 'West', 'Central']
# Generate 1000 records
data = []
end_date = datetime.now()
start_date = end_date - timedelta(days=365)
for i in range(1000):
category = random.choice(list(categories.keys()))
product = random.choice(categories[category])
date = start_date + timedelta(days=random.randint(0, 365))
# Some missing values (5% chance)
quantity = random.randint(1, 50) if random.random() > 0.05 else None
price = round(random.uniform(10, 1000), 2) if random.random() > 0.05 else None
data.append({
'date': date.strftime('%Y-%m-%d'),
'product_name': product,
'category': category,
'region': random.choice(regions),
'quantity': quantity,
'price': price,
'cost': round(random.uniform(5, 800), 2) if price else None
})
df = pd.DataFrame(data)
# Create data directory if not exists
import os
os.makedirs('data', exist_ok=True)
# Save to CSV
output_file = 'data/raw_sales_data.csv'
df.to_csv(output_file, index=False)
print(f"✅ Sample data created: {output_file}")
print(f"📊 Total records: {len(df)}")
print("\nFirst 5 rows:")
print(df.head())
return df
if __name__ == "__main__":
generate_sample_data()