Generation of large CSV data using Python Faker library. | by Krishna Parekh | Towards Data Science

To the learners out there, who need large amount of fake data to experiment different algorithm. Mammoth data is generated online each second in various domains but for learning and experimenting purpose, the original data can’t be used due to security and many other constraints. So here I am talking about huge amount of fake data generation using a library called Faker with Python.
Faker is a Python package that generates fake data.
Installing Faker library using pip:
pip install Faker
faker.Faker() initializes a fake generator which can generate data for different properties based on different data types. Different properties of faker generator are packaged in “providers”. The list of different faker providers can be found here. It also has internet providers for ipv4 and other community providers like web, cloud and wifi. Custom Providers can be created and added using fake.add_provider(CustomProvider).
Some of the fake generators for different data types are illustrated below. More detailed use of different providers is given in this notebook.
from faker import Fakerfrom faker.providers import internetfake = Faker()fake.pybool()   # Randomly returns True/Falseprint(fake.pyfloat(left_digits=3, right_digits=3, positive=False, min_value=None, max_value=None))   # Float dataprint(fake.pystr(min_chars=None, max_chars=10))  # String dataprint(fake.pylist(nb_elements=5, variable_nb_elements=True))  # Listfake.add_provider(internet)print(fake.ipv4_private())  # Fake ipv4 address
The data output looks like this:
faker.Faker() can take a locale as an argument, to return localized data. Default locale is en_US. It has support for languages like Hindi, French, Spanish, Chinese, Japanese, Arabic, German and many more.
from faker import Fakerfake_H = Faker('hi_IN')   # To generate Hindi Fake datafake_H.name()
Faker can also be invoked from command-line after installation.
faker [-h] [--version] [-o output]      [-l {bg_BG,cs_CZ,...,zh_CN,zh_TW}]      [-r REPEAT] [-s SEP]      [-i {package.containing.custom_provider otherpkg.containing.custom_provider}]      [fake] [fake argument [fake argument ...]]where;-h, --help : shows a help message--version : shows the program version-o : output file[-l {bg_BG,cs_CZ,...,zh_CN,zh_TW}] : allows using localized provider[-r REPEAT] : To generate specified number of outputs[-s SEP] : Separator to separate generated outputs[-i {package.containing.custom_provider otherpkg.containing.custom_provider}] : to add custom providers[fake] : name of fake to generate an output for (e.g. name, address)
Large CSV files with fake data can be generated very easily with any number of records. All you need to do is just pass headers of CSV and specify data property for each column in header.
Faker facilitates the data generation of types such as name, email, url, address, phone number, zip code, city, state, country, date, time and many more. The code to generate fake CSV data is given below.
You can find the code files here. Hope you found this reading helpful and it provided some meaningful insights to you! Your valuable feedbacks are most welcomed. Happy Learning !!!