Generating data Python faker

https://faker.readthedocs.io/en/master/locales.html

Faker is a Python package, GITHUB open source projects, mainly used to create dummy data, use Faker package, no longer need to manually generate random numbers generated or hand-written data, simply call the method Faker provided to complete the generated data.

https://github.com/joke2k/faker

language support:

  • Simplified Chinese: zh_CN

  • Traditional Chinese: zh_TW

  • American English: en_US

  • British English: en_GB

  • 德文: de_DE

  • Japanese: ja_JP

  • 韩文: ko_KR

  • 法文: fr_FR

conda installation faker

(base) [root@pyspark ~]# conda install faker
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

environment location: /root/anaconda3

added / updated specs:
- faker


The following packages will be downloaded:

package | build
---------------------------|-----------------
ca-certificates-2019.10.16 | 0 131 KB
certifi-2019.9.11 | py37_0 154 KB
conda-4.7.12 | py37_0 3.0 MB
faker-2.0.2 | py37_0 1.4 MB
openssl-1.1.1d | h7b6447c_3 3.7 MB
text-unidecode-1.2 | py37_0 63 KB
------------------------------------------------------------
Total: 8.5 MB

The following NEW packages will be INSTALLED:

faker pkgs/main/linux-64::faker-2.0.2-py37_0
text-unidecode pkgs/main/linux-64::text-unidecode-1.2-py37_0

The following packages will be UPDATED:

ca-certificates conda-forge::ca-certificates-2019.9.1~ --> pkgs/main::ca-certificates-2019.10.16-0
openssl conda-forge::openssl-1.1.1c-h516909a_0 --> pkgs/main::openssl-1.1.1d-h7b6447c_3

The following packages will be SUPERSEDED by a higher-priority channel:

certifi conda-forge --> pkgs/main
conda conda-forge --> pkgs/main


Proceed ([y] / n)? Y


Downloading and Extracting Packages
openssl-1.1.1d | 3.7 MB | ############################################################################################################# | 100%
certifi-2019.9.11 | 154 KB | ############################################################################################################# | 100%
faker-2.0.2 | 1.4 MB | ############################################################################################################# | 100%
conda-4.7.12 | 3.0 MB | ############################################################################################################# | 100%
text-unidecode-1.2 | 63 KB | ############################################################################################################# | 100%
ca-certificates-2019 | 131 KB | ############################################################################################################# | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

(base) [root@pyspark faker]# faker --version
faker 2.0.2

from faker import Faker
f = Faker(locale="zh_CN")
for i in range(10):
print(f.name()+" "+f.address()+f.phone_number())

 

(base) [root @ pyspark faker ] # python fakertest.py
Li Xiulan, Henan Province into the city Daxing Road, a seat 55025418524143216 Joe
Liu Yang Yan, Jiangsu Province, Liuzhou City, Metro Road Block D 75452313589587678
Liu Ping, Guizhou Province, Harbin Road, Harbor City Lijuan e seat 52287118026178868
Maxiu Fang took to the streets of Wuhan City, Fujian Province Zhangjiagang Street q seat 91655718227982978
sand Guiying Xu Zhao County, Anhui Province Huangpu Street Block I 51022114735698739
Zhou Chunmei Shen Xin Chongqing City Hehai opportunities seat I 76978313142741948
Cheng Yong Ping Shan County of Xinjiang Uygur Autonomous Region cinnamon Fuxin Road, Block Q 27110713644789383
yellow just Beijing Shenzhen harbor Wing Street Block D 17260513527084118
Li Qian County, Xinjiang Uygur Autonomous Region has just Liangping Cheng Du Road m seat 31005215886267016
history of Inner Mongolia Autonomous Region Na Gao Yuhua Heping Street Block Z 85075015187273133

Package:

from faker import Faker

MyFaker class:
DEF __init __ (Self):
# Select Chinese language
self.fake = Faker ( "zh_CN")

def gen_name(self):
return self.fake.name()

def gen_address(self):
return self.fake.address()

def gen_phon_number(self):
return self.fake.phone_number()

if __name__ == "__main__":
fake1 = MyFaker()
for i in range(10):
print(fake1.gen_name()+" "+fake1.gen_address()+" "+fake1.gen_phon_number())

Wang Yang, Liaoning Province, Xi'an, Xishan chapter Street s seat 106,151 15,633,984,776
Ningde County, Hainan Province, and Yang Yulan platform North Block G 589 158 15242655224
Sheng Zhiqiang Harbin City, Jiangsu Province, Xishan Shenyang Road j seat 971 375 18253873299
build Huaxi Yuan County, Taiwan Province, Lei N Street Block 150 622 13654485648
Ouyang Yuying Tianjin Ting County, six special blue road j seat 347 271 18131690076
Xu Shuzhen Tianjin Ping Wei Gaoping City Road, Block F 777 941 13,583,020,064
single sensitive Xinji County, Chongqing City, Sandy Bay Street Zhangjiagang e seat 803,072 18,238,051,669
fee Yunnan Jie Wang Xiuying County Mentougou Street Block L 407805 18953467968
Li Ying Chen Yu County Special Administrative Region Xishan Road Block f 108 237 18258526522
Wu Xin Xinjiang Uygur Autonomous Region Hui Mei County east Street, z seat 955 573 18042203851

 

Examples of each fake call  name()when the method will produce different random names. There are many methods available fake example, these methods are divided into the following categories:

  • address address
  • person character classes: gender, name, etc.
  • barcode barcode class
  • color class color
  • company Company categories: company name, company email, company name prefixes
  • credit_card bank cards: the card number, expiration date, type, etc.
  • currency Currency
  • date_time date categories: date, year, month, etc.
  • file class file: file name, file type, file extension, etc.
  • internet Internet category
  • job work
  • lorem random number 假文
  • misc Miscellaneous Class
  • phone_number phone number: mobile phone number, business segment operating
  • python python data
  • profile character description information: name, gender, address, company, etc.
  • ssn social security number (ID number)
  • user_agent user agent

Guess you like

Origin www.cnblogs.com/songyuejie/p/11824812.html