说明
《Python 教程》 持续更新中,提供建议、纠错、催更等加作者微信: gairuo123(备注:pandas教程)和关注公众号「盖若」ID: gairuo。跟作者学习,请进入 Python学习课程。欢迎关注作者出版的书籍:《深入浅出Pandas》 和 《Python之光》。
Faker 是一个 Python软件包,可以成伪造数据。 无论是需要导入数据库,创建美观的 XML 文档,填充数据进行压力测试,Faker 都是您的理想之选。
仅支持 Python 3.5+。
pip install Faker
from faker import Faker
fake = Faker('zh-CN') # 生成中文资料,默认为英文
fake.name() # 姓名
# '王秀华'
fake.user_agent() # 用户代理
# 'Opera/8.18.(Windows CE; eu-ES) Presto/2.9.170 Version/12.00'
fake.swift()
# NOJUGBX3
fake.swift11()
# KZWGGBREE0B
fake.swift8()
# ZUUTGBPK
fake.ssn()
# 51018119550115198X
fake.street_address()
# 李街i座
fake.street_name()
# 葛路
fake.street_suffix()
# 路
fake.boolean()
# True
fake.bothify()
# 71 Oc
fake.bs()
# transform e-business e-commerce
fake.building_number()
# I座
fake.cache_pattern()
# fake.catch_phrase()
# Face-to-face national matrix
fake.century()
# IV
fake.chrome()
# Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/536.0 (KHTML, like Gecko) CriOS/61.0.829.0 Mobile/56S470 Safari/536.0
fake.city()
# 娟县
fake.city_name()
# 哈尔滨
fake.city_suffix()
# 县
fake.color()
# #eeccff
fake.color_name()
# LightPink
fake.company()
# 国讯网络有限公司
fake.company_email()
# lujing@ed.cn
fake.company_prefix()
# 凌颖信息
fake.company_suffix()
# 网络有限公司
fake.coordinate()
# 142.578486
fake.country()
# 东萨摩亚
fake.credit_card_number()
# 4540767786851462
fake.credit_card_provider()
# VISA 16 digit
fake.credit_card_security_code()
# 665
fake.cryptocurrency()
# ('STC', 'SwiftCoin')
fake.cryptocurrency_code()
# BC
fake.cryptocurrency_name()
# TRON
fake.csv()
# "陶波","陕西省通辽县东城西宁路J座 843194" ....
fake.currency()
# ('EUR', 'Euro')
fake.currency_code()
# KMF
fake.currency_name()
# Fijian dollar
fake.currency_symbol()
# ₡
fake.date()
# 1972-10-11
fake.date_between()
# 2016-12-19
fake.date_between_dates()
# 2020-09-07
fake.date_object()
# 1990-12-19
fake.date_of_birth()
# 1946-07-27
fake.date_this_century()
# 2009-10-22
fake.date_this_decade()
# 2020-08-23
fake.date_this_month()
# 2020-09-06
fake.date_this_year()
# 2020-01-16
fake.date_time()
# 1976-07-26 16:01:23
fake.date_time_ad()
# 1254-08-02 23:10:36
fake.date_time_between()
# 1998-12-15 19:26:45
fake.date_time_between_dates()
# 2020-09-07 18:08:34
fake.date_time_this_century()
# 2016-04-02 23:12:48
fake.date_time_this_decade()
# 2020-08-19 05:04:37
fake.date_time_this_month()
# 2020-09-04 09:57:19
fake.date_time_this_year()
# 2020-06-24 09:44:51
fake.day_of_month()
# 12
fake.day_of_week()
# Monday
fake.del_arguments()
# fake.dga()
# obvunayjqeoo.cn
fake.district()
# 双滦
fake.domain_name()
# weijun.cn
fake.domain_word()
# nayang
fake.dsv()
# "沈敏","澳门特别行政区宜都县和平王路L座 104172" ...
fake.ean()
# 6269147934409
fake.ean13()
# 9520386433052
fake.ean8()
# 92288805
fake.email()
# pgong@hotmail.com
fake.factories()
# fake.file_extension()
# wav
fake.file_name()
# 帮助.numbers
fake.file_path()
# /喜欢/功能.numbers
fake.firefox()
# Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_10_6; rv:1.9.6.20) Gecko/2010-05-05 01:08:50 Firefox/3.6.15
fake.first_name()
# 桂荣
fake.first_name_female()
# 雪
fake.first_name_male()
# 平
fake.first_name_nonbinary()
# 敏
fake.first_romanized_name()
# Fang
fake.fixed_width()
# 魏玉 1
# 滕颖 7
# ...
fake.free_email_domain()
# yahoo.com
fake.future_date()
# 2020-09-26
fake.future_datetime()
# 2020-09-14 02:01:18
fake.hex_color()
# #2f4594
fake.hexify()
# cffc
fake.hostname()
# srv-90.99.cn
fake.http_method()
# HEAD
fake.iban()
# GB14PIQS18540185340513
fake.image_url()
# https://www.lorempixel.com/179/437
fake.internet_explorer()
# Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/5.0)
fake.ios_platform_token()
# iPhone; CPU iPhone OS 9_3_6 like Mac OS X
fake.ipv4()
# 84.153.27.81
fake.ipv4_network_class()
# c
fake.ipv4_private()
# 10.198.130.107
fake.ipv4_public()
# 197.103.29.90
fake.ipv6()
# 62de:c8cf:635a:faff:3ea6:1d6f:5d6c:f4cd
fake.isbn10()
# 1-62630-265-0
fake.isbn13()
# 978-0-477-18738-1
fake.iso8601()
# 2005-01-12T00:55:10
fake.items()
# odict_items([('zh_CN', <faker.generator.Generator object at 0x7fbeef06eb80>)])
fake.job()
# 船长/副船长
fake.json()
# [{"name": "\u5f20\u521a", "residency": "\u ...
fake.language_code()
# lt
fake.language_name()
# Corsican
fake.last_name()
# 唐
fake.last_name_female()
# 曾
fake.last_name_male()
# 周
fake.last_name_nonbinary()
# 俞
fake.last_romanized_name()
# Li
fake.latitude()
# 83.665437
fake.latlng()
# (Decimal('-54.488602'), Decimal('-34.334857'))
fake.lexify()
# NyOq
fake.license_plate()
# 62-9200G
fake.linux_platform_token()
# X11; Linux x86_64
fake.linux_processor()
# i686
fake.local_latlng()
# ('33.76446', '-117.79394', 'North Tustin', 'US', 'America/Los_Angeles')
fake.locale()
# th_TH
fake.locales()
# fake.localized_ean()
# 1018723876900
fake.localized_ean13()
# 0592770275691
fake.localized_ean8()
# 11052463
fake.location_on_land()
# ('49.65186', '26.97253', 'Krasyliv', 'UA', 'Europe/Kiev')
fake.longitude()
# -141.898521
fake.mac_address()
# 7e:09:12:47:35:74
fake.mac_platform_token()
# Macintosh; Intel Mac OS X 10_12_1
fake.mac_processor()
# Intel
fake.md5()
# 880a68e2bbfeb2d8b6a54954b4d54f85
fake.mime_type()
# multipart/encrypted
fake.month()
# 01
fake.month_name()
# April
fake.msisdn()
# 3486522337296
fake.name()
# 杨婷婷
fake.name_female()
# 周岩
fake.name_male()
# 李玉兰
fake.name_nonbinary()
# 李璐
fake.null_boolean()
# None
fake.numerify()
# 806
fake.opera()
# Opera/9.39.(Windows 95; wae-CH) Presto/2.9.172 Version/12.00
fake.paragraph()
# 公司组织那些不是在线部分.作品得到汽车他们成功行业最新.支持怎么详细出现.
fake.paragraphs()
# ['事情很多喜欢.管理中文所有.您的积分关于查看学校.', '无法怎么中心服务.客户报告方式合作提高一点.', '什么东西游戏政府.不要中国记者注意.']
fake.parse()
# fake.password()
# h3BfoGJg&8
fake.past_date()
# 2020-08-23
fake.past_datetime()
# 2020-09-02 09:51:10
fake.phone_number()
# 15317222151
fake.phonenumber_prefix()
# 157
fake.port_number()
# 9910
fake.postcode()
# 597832
fake.profile()
# {'job': '报关与报检', 'company': '浦华众城科技有限公司', 'ssn':...
fake.psv()
# "方玉"|"河北省长春市滨城沈阳路I座 808404"...
fake.pybool()
# True
fake.pydecimal()
# 25.5170909
fake.pydict()
# {'你的': 'BYlOPYmKnalLAskuYrEL', '根据': 'http://www.yan.net/login/', '出来': datetime(2000, 3, 11, 21, 24, 57), '说明': Decimal('30648.2'), '他们': 'gRPbWHmmAlfuaUrWgaqF', '音乐': Decimal('-90.915884731'), '记者': 'vwtHOdANYUinFYMxWsBX', '是否': Decimal('-191357690704975.0'), '文件': -541.5049873291}
fake.pyfloat()
# 2907.0
fake.pyint()
# 6764
fake.pyiterable()
# [13214881.5324, 8884, 'nBPqeieociQnYkDLcokv', 'xiongjie@09.cn', 'TMHkKWYgJhbgtQkTHzTE', 'WazkFVHCFxJkQzjirUjY']
fake.pylist()
# ['jingcheng@xiaokong.cn', datetime(2009, 10, 28, 4, 46, 17), Decimal('-446703581.97'),...
fake.pyset()
# {'NKKscNgbJdRBztqzpShB', 510088554.4388, 'http://www.lei.cn/list/search/', 'UbqHIkhppydBodjvMYXz', 'http://66.cn/', 'qiaoxia@gmail.com', 'jshi@yahoo.com', datetime(2006, 7, 6, 22, 58, 59), datetime(1973, 5, 12, 14, 5, 18)}
fake.pystr()
# AjyPRjRPqGQlwHXJnIZM
fake.pystr_format()
# O4-6705652R
fake.pystruct()
# ([-93614.522, 'QxedIAEryHrErJDmVqPw',...
fake.pytimezone()
# tzfile('/usr/share/zoneinfo/Africa/Casablanca')
fake.pytuple()
# (datetime(2006, 5, 10, 22, 58, 34), -3833240.5, ...
fake.random()
# fake.random_choices()
# ['b', 'b']
fake.random_digit()
# 9
fake.random_digit_not_null()
# 7
fake.random_digit_not_null_or_empty()
#
fake.random_digit_or_empty()
# 6
fake.random_element()
# c
fake.random_elements()
# ['c', 'a', 'c']
fake.random_int()
# 3868
fake.random_letter()
# J
fake.random_letters()
# ['F', 'j', 'n', 'n', 'R', 'p', 'H', 'J', 'c', 'e', 'P', 'M', 'D', 'K', 'S', 'R']
fake.random_lowercase_letter()
# p
fake.random_number()
# 25811529
fake.random_sample()
# ['b', 'a', 'c']
fake.random_uppercase_letter()
# A
fake.randomize_nb_elements()
# 8
fake.rgb_color()
# 114,200,183
fake.rgb_css_color()
# rgb(113,146,219)
fake.romanized_name()
# Ping Fu
fake.safari()
# Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6 rv:3.0; nl-AW) AppleWebKit/531.4.6 (KHTML, like Gecko) Version/5.1 Safari/531.4.6
fake.safe_color_name()
# fuchsia
fake.safe_domain_name()
# example.net
fake.safe_email()
# zhengxiuying@example.org
fake.safe_hex_color()
# #ffaa00
fake.seed()
# fake.seed_instance()
# None
fake.seed_locale()
# fake.sentence()
# 图片感觉要求过程以后一点国际.
fake.sentences()
# ['这个音乐时间可以.', '一定时间原因作品介绍东西全部加入.', '最后同时那个本站是否基本.']
fake.sha1()
# 2f99f3e98a4934a310278e9982f79435b9a7397f
fake.sha256()
# 3a01a0216a82cfe518dcde995519077abefb3b21bc58c958d800b16670affc78
fake.simple_profile()
# {'username': 'yong62', 'name': '孙娜', 'sex': 'F', 'address': '河北省通辽县南长佛山街L座 475667', 'mail': 'weilong@yahoo.com', 'birthdate': date(1974, 5, 8)}
以下为部分数据类型生成方法名,有些可以传相应的参数。
'''
'address',
'am_pm',
'android_platform_token',
'ascii_company_email',
'ascii_email',
'ascii_free_email',
'ascii_safe_email',
'bank_country',
'bban',
'binary',
'boolean',
'bothify',
'bs',
'building_number',
'cache_pattern',
'catch_phrase',
'century',
'chrome',
'city',
'city_name',
'city_suffix',
'color',
'color_name',
'company',
'company_email',
'company_prefix',
'company_suffix',
'coordinate',
'country',
'country_calling_code',
'country_code',
'credit_card_expire',
'credit_card_full',
'credit_card_number',
'credit_card_provider',
'credit_card_security_code',
'cryptocurrency',
'cryptocurrency_code',
'cryptocurrency_name',
'csv',
'currency',
'currency_code',
'currency_name',
'currency_symbol',
'date',
'date_between',
'date_between_dates',
'date_object',
'date_of_birth',
'date_this_century',
'date_this_decade',
'date_this_month',
'date_this_year',
'date_time',
'date_time_ad',
'date_time_between',
'date_time_between_dates',
'date_time_this_century',
'date_time_this_decade',
'date_time_this_month',
'date_time_this_year',
'day_of_month',
'day_of_week',
'del_arguments',
'dga',
'district',
'domain_name',
'domain_word',
'dsv',
'ean',
'ean13',
'ean8',
'email',
'factories',
'file_extension',
'file_name',
'file_path',
'firefox',
'first_name',
'first_name_female',
'first_name_male',
'first_name_nonbinary',
'first_romanized_name',
'fixed_width',
'format',
'free_email',
'free_email_domain',
'future_date',
'future_datetime',
'generator_attrs',
'get_arguments',
'get_formatter',
'get_providers',
'hex_color',
'hexify',
'hostname',
'http_method',
'iban',
'image_url',
'internet_explorer',
'ios_platform_token',
'ipv4',
'ipv4_network_class',
'ipv4_private',
'ipv4_public',
'ipv6',
'isbn10',
'isbn13',
'iso8601',
'items',
'job',
'json',
'language_code',
'language_name',
'last_name',
'last_name_female',
'last_name_male',
'last_name_nonbinary',
'last_romanized_name',
'latitude',
'latlng',
'lexify',
'license_plate',
'linux_platform_token',
'linux_processor',
'local_latlng',
'locale',
'locales',
'localized_ean',
'localized_ean13',
'localized_ean8',
'location_on_land',
'longitude',
'mac_address',
'mac_platform_token',
'mac_processor',
'md5',
'mime_type',
'month',
'month_name',
'msisdn',
'name',
'name_female',
'name_male',
'name_nonbinary',
'null_boolean',
'numerify',
'opera',
'paragraph',
'paragraphs',
'parse',
'password',
'past_date',
'past_datetime',
'phone_number',
'phonenumber_prefix',
'port_number',
'postcode',
'prefix',
'prefix_female',
'prefix_male',
'prefix_nonbinary',
'profile',
'provider',
'providers',
'province',
'psv',
'pybool',
'pydecimal',
'pydict',
'pyfloat',
'pyint',
'pyiterable',
'pylist',
'pyset',
'pystr',
'pystr_format',
'pystruct',
'pytimezone',
'pytuple',
'random',
'random_choices',
'random_digit',
'random_digit_not_null',
'random_digit_not_null_or_empty',
'random_digit_or_empty',
'random_element',
'random_elements',
'random_int',
'random_letter',
'random_letters',
'random_lowercase_letter',
'random_number',
'random_sample',
'random_uppercase_letter',
'randomize_nb_elements',
'rgb_color',
'rgb_css_color',
'romanized_name',
'safari',
'safe_color_name',
'safe_domain_name',
'safe_email',
'safe_hex_color',
'seed',
'seed_instance',
'seed_locale',
'sentence',
'sentences',
'set_arguments',
'set_formatter',
'sha1',
'sha256',
'simple_profile',
'slug',
'ssn',
'street_address',
'street_name',
'street_suffix',
'suffix',
'suffix_female',
'suffix_male',
'suffix_nonbinary',
'swift',
'swift11',
'swift8',
'tar',
'text',
'texts',
'time',
'time_delta',
'time_object',
'time_series',
'timezone',
'tld',
'tsv',
'unix_device',
'unix_partition',
'unix_time',
'upc_a',
'upc_e',
'uri',
'uri_extension',
'uri_page',
'uri_path',
'url',
'user_agent',
'user_name',
'uuid4',
'weights',
'windows_platform_token',
'word',
'words',
'year',
'zip'
'''
todo
更新时间:2020-09-07 18:16:22 标签:测试 数据 数据集