How to generate random fake data using faker in python

Dummy Data Using Faker Package in Python for Data Science

Gautamankul
3 min readApr 28, 2022

Rinu Gour TDS Editors Aman Kharwal

Dummy Data Using Faker Package in Python for Data Science

Hello Developer’ s today we are learn create fake data and know about Fake Library in python3…

Prerequisite:

  1. Python
  2. Faker (package)

What is Faker:

Faker is a Python package that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in your persistence to stress test it, or anonymize data taken from a production service, Faker is for you. let’s install faker library

python3 -m pip install Faker

If you are using python language, you can use a faker python package to create dummy data of any type, for example, dates, transactions, names, texts, time, and others. Faker is a simple python package that generates fake data with different data types.

Table of content’s:

  1. Create Faker Generator
  2. Create Names
  3. Create Dates and Times
  4. Create Personal Profile
  5. Create Sentence & Paragraph Data
  6. Create Localized Data
  7. Create the same Fake Data
  8. Reference

Create Fake Dummy Data :

To create and initialize a faker generator use the Faker() method for a specific country. Here I’m using for India.

from faker import Faker
fake = Faker('hi_IN')

Let’s create some information like Names, Datetime and location.

for _ in range(5):
print(fake.name())#outputमल्लिक, अंकुर
विकावि, रतन
बसु, आरुष
विक्रम बापट
भंडारी, मोहन

If you are working with dates, faker provides different ways to create fake dates and times. In the following examples, you will learn 10 different ways to create dummy dates and times data.

print(fake.month())print(fake.date_time())print(fake.year())print(fake.month_name())print(fake.date_time_this_year())print(fake.time())print(fake.timezone())print(fake.day_of_week())print(fake.time_object())

Create a Personal Profile:

If you want to create fake personal and identity information you can use the profile and simple profile methods from the faker library. The simple profile method creates a fake basic profile with personal information such as name, gender, mail, and address.

print(fake.simple_profile())#output{'username': 'amrdttaa', 'name': 'कृष्णन, एषा', 'sex': 'M', 'address': '91 वफादार\nहैदराबाद 203271', 'mail': 'ddaaniianaayaa@hotmail.com', 'birthdate': datetime.date(1966, 9, 23)}

Now we are move to create and render in tabluar form so we just use Pandas Library.

import pandas as pd
data = [fake.profile()for i in range(10)]
#save profiles in pandas dataframedf = pd.DataFrame(data)
print(df)

output of data frame is……

All of this we are also create and Generate a Basic Bank Account Number (BBAN) And SWIFT number let’s do that..

from faker import Faker
fake = Faker('hi_IN')
for _ in range(5):
print('Bank Account :',fake.bban())
print(f'SWIFt Code ',fake.swift())# OutPutBank Account : IXLJ09018582577136
SWIFt Code NZMUGBPXY6MBank Account : RMHS26077387622870
SWIFt Code IKNVGBC0Bank Account : BWMH78522673605843
SWIFt Code DMJWGB1D

Why faker library are used? :

Faker is an open-source python library that allows you to create your own dataset i.e you can generate random data with random attributes like name, age, location, etc.

It is used in datascience for fake data insertion and operation perform of each data sets.

If you want to learn more about Faker library then use faker documentations.

faker.readthedocs.io

Good Bye Developer’s, Want to read more articles like this follow me and clap for this article!

--

--

Gautamankul

A Software Developer Engineer & Entrepreneur and along with i am a Buddhist.