用faker模拟数据+随机种子
%config ZMQInteractiveShell.ast_node_interactivity='all'
%pprint
Pretty printing has been turned OFF
导入工具包
import pandas as pd
from faker import Faker
创建实例,设置本地化
fake = Faker('zh_CN')
创建模拟个人数据函数,设定随机种子
def generate_user(i):
fake.random.seed(i)
return dict(name=fake.name(),password=fake.password(length=10),company=fake.company(),job=fake.job(),birthday=fake.date_of_birth(minimum_age=0, maximum_age=120),
telephone=fake.phone_number(),
address=fake.address())
生成客户模拟数据列表, 用dataframe呈现
users = []
for i in range(5):
users.append(generate_user(i))
df = pd.DataFrame(users)
df
验证随机种子设定是否成功
users = []
for i in range(8):
users.append(generate_user(i))
df = pd.DataFrame(users)
df
导出数据,生成csv文件
df.to_csv('./fakedata.csv')
查看博客资料
资料索引