-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproductInfo_dummy.py
More file actions
49 lines (36 loc) · 1.17 KB
/
productInfo_dummy.py
File metadata and controls
49 lines (36 loc) · 1.17 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
from faker import Faker
import random
import pandas as pd
import numpy as np
import config
from sqlalchemy import create_engine
import sqlalchemy as db
fake = Faker('ko_KR') # locale 정보 설정
Faker.seed() # 초기 seed 설정
num = 1000000
# 상품 번호
# productId = [i for i in range(1, num+1)]
productId = [i for i in range(1000001, 2000001)]
print(productId)
ten = [random.randint(0,10) for i in range(num)]
twenty = [random.randint(0,10) for i in range(num)]
thirty = [random.randint(0,7) for i in range(num)]
forty = [random.randint(0,5) for i in range(num)]
df = pd.DataFrame()
df['product_info_id'] = productId
df['ten'] = ten
df['twenty'] = twenty
df['thirty'] = thirty
df['over_forty'] = forty
records = df.to_dict(orient='records')
port = config.port
username = config.username
password = config.password
host = config.host
dbname = config.dbname
engine = create_engine(f"mysql://{username}:{password}@{host}:{port}/{dbname}?charset=utf8mb4")
with engine.connect() as conn:
metadata = db.MetaData()
table = db.Table('product_info', metadata, autoload=True, autoload_with=engine)
query = db.insert(table).values(records)
result_proxy = conn.execute(query)