pip install Faker
#
创建虚拟姓名、电话号码、地址等信息:
from faker import Faker fake = Faker() fake.name() # 'Jonathon Dixon' fake.phone_number() # '262-035-1927' fake.address() # '590 Hart Motorway\nSergioshire, NM 76453'
2.2 国内信息
from faker import Faker fake = Faker('zh_CN') fake.name() # '汪雪梅' fake.phone_number() # '18535612607' fake.address() # '重庆市秀云县静安潜江街X座 690499'
是不是可以假乱真~
ar_EG - Arabic (Egypt) ar_PS - Arabic (Palestine) ar_SA - Arabic (Saudi Arabia) bg_BG - Bulgarian bs_BA - Bosnian cs_CZ - Czech de_DE - German dk_DK - Danish el_GR - Greek en_AU - English (Australia) en_CA - English (Canada) en_GB - English (Great Britain) en_NZ - English (New Zealand) en_US - English (United States) es_ES - Spanish (Spain) es_MX - Spanish (Mexico) et_EE - Estonian fa_IR - Persian (Iran) fi_FI - Finnish fr_FR - French hi_IN - Hindi hr_HR - Croatian hu_HU - Hungarian hy_AM - Armenian it_IT - Italian ja_JP - Japanese ka_GE - Georgian (Georgia) ko_KR - Korean lt_LT - Lithuanian lv_LV - Latvian ne_NP - Nepali nl_NL - Dutch (Netherlands) no_NO - Norwegian pl_PL - Polish pt_BR - Portuguese (Brazil) pt_PT - Portuguese (Portugal) ro_RO - Romanian ru_RU - Russian sl_SI - Slovene sv_SE - Swedish tr_TR - Turkish uk_UA - Ukrainian zh_CN - Chinese (China Mainland) zh_TW - Chinese (China Taiwan)
2.3 生成个人档案信息
fake.profile(fields=None, sex=None)
2.4 批量生成人员信息
import collections import ngender import datetime import pandas as pd all_info = [] pa_list = ['name','gender', 'age', 'job', 'company', 'address', 'phone_number', 'company_email'] for i in range(15): people = collections.namedtuple('User', pa_list) people.name = fake.name() people.gender = '男' if ngender.guess(people.name)[0] == 'male' else '女' people.age = datetime.datetime.now().year - fake.date_of_birth(tzinfo=None, minimum_age=25, maximum_age=40).year # 出生日期 people.job = fake.job() people.company = fake.company() people.address = fake.address().split(' ')[0] people.phone_number = fake.phone_number() people.company_email = fake.company_email() lsts = [people.name, people.gender, people.age, people.job, people.company, people.address, people.phone_number, people.company_email] all_info.append(lsts) pd.DataFrame(all_info,columns=pa_list)
address 地址
person 人物类
barcode 条码类
color 颜色类
company 公司类
credit_card 银行卡类
currency 货币
date_time 时间日期类
file 文件类
internet 互联网类
job 工作
lorem 乱数假文
misc 杂项类
phone_number 手机号
python python数据
profile 档案信息
ssn 身份证号码
user_agent 用户代理
官方文档:
以上是技巧 | 一個以假亂真的Python庫,我裂開了。 。的詳細內容。更多資訊請關注PHP中文網其他相關文章!