Q： データ分析用に架空のデータを作成してください．行数は50行とします．

A：以下に架空のデータセットを示します．顧客の情報，注文情報，売り上げ情報などを表す5つのフィールドで構成されています：customer_id（顧客ID），age（年齢），product（製品），order_date（注文日），sales（売上）．

(略)

Q：
上記のデータに以下の点を考慮してください．
- salesはある程度年齢の増加にたいして増加傾向にある．
- order_dateは完全にランダム．ただし，1月～3月の範囲にあること．
- プロダクトの数を増やす．20商品ある．
- 各商品にたいして「単価」を追加．
- `customer_id`にたいして，「年収」を追加

A：

ご指定の内容に従って新たな架空のデータを生成します．

以下の点を考慮しています：

1.「sales」は年齢に応じて増加します．具体的には，年齢にランダムな係数を掛けたものを売上とします．
2.「order_date」は2023年1月から3月の間でランダムに生成します．
3.20種類の商品があります．それぞれが等確率で選ばれます．
4.各商品には「単価」があります．単価は商品ごとに一定で，10から100までの整数とします．
5.「customer_id」に対応する「年収」を追加します．「年収」は年齢にランダムな係数を掛けたものとします．

Pythonのpandasとnumpyを使ってデータを生成します．


```python

import pandas as pd
import numpy as np
from random import randint, choice
from pandas.tseries.offsets import DateOffset

# 固定の乱数シードを設定します（再現性のため）
np.random.seed(0)

num_rows = 50
product_names = [f'Product{i}' for i in range(1, 21)] # 20 products
unit_prices = {product: randint(10, 100) for product in product_names} # Unit price per product

# DataFrameを生成します
data = {
    'customer_id': range(1, num_rows + 1),
    'age': np.random.randint(20, 60, num_rows), # Age between 20 and 60
    'product': [choice(product_names) for _ in range(num_rows)], # Randomly choose a product
    'order_date': [pd.Timestamp('2023-01-01') + DateOffset(days=randint(0, 90)) for _ in range(num_rows)], # Random date between January and March
}

df = pd.DataFrame(data)
df['unit_price'] = df['product'].map(unit_prices) # Map unit price from product
df['sales'] = df['unit_price'] * df['age'] + np.random.normal(scale=100, size=num_rows) # Age-dependent sales
df['income'] = df['age'] * 1000 + np.random.normal(scale=5000, size=num_rows) # Age-dependent income

df.head()
```
