Python 3 Pandas Script to Generate Fake Random User Data in Excel,CSV & JSON File Using NumPy
Jun 3, 2025
Get the full source code of application here:
https://codingshiksha.com/python/python-3-pandas-script-to-generate-fake-random-user-data-in-excelcsv-json-file-using-numpy/
Show More Show Less View Video Transcript
0:00
uh hello guys uh welcome to this video
0:02
so in this video I will show you how to
0:04
generate a random set of tabular data in
0:08
different format CSV Excel file and JSON
0:10
file sometimes inside your application
0:13
if you are need some kind of random data
0:16
for a API testing or any sort of
0:19
application testing then this script
0:20
will be very much useful uh it uses two
0:24
libraries of Python uh pandas libraries
0:27
and numpy so as you can see we are
0:30
generating 100 rows of uh user data and
0:34
uh it contains these four columns name
0:37
age country marks you can actually
0:39
change uh any sort of columns you just
0:42
need to provide the column names and the
0:43
actual
0:44
schema so then it will generate uh the
0:48
random set of user data so as I execute
0:52
the script here let me show you it will
0:55
generate the data in all the formats
1:00
first of all you need to install the
1:02
necessary packages and as you can see it
1:05
has
1:06
uh generated the data in CSV format JSON
1:10
format and Excel format all the
1:14
three extensions of data has been
1:16
successfully generated if I open the CSV
1:19
file here you will
1:20
see it has generated uh
1:24
100 users name age uh country and marks
1:30
similarly for JSON as well you will see
1:32
it has created this array of objects
1:35
each object is having the property four
1:38
properties name age mark country and
1:40
marks and this is your Excel file here
1:42
as well it is actually containing this
1:45
sheet of data 100 users are there name
1:49
age country
1:50
marks
1:52
so as I already told you need to install
1:55
some modules for this
1:57
uh first of all we are using this
2:00
popular package which is pandas package
2:03
it's a powerful package for data
2:05
analysis so simply install this by
2:08
executing this command and also we need
2:11
the numpy package as well which is also
2:14
a very popular package in python for
2:16
array computing so simply install this
2:18
by executing this command as well so
2:21
after you install this we just need to
2:23
create a simple app py file
2:28
so so the very first thing we need to do
2:30
you just need to import the necessary
2:32
packages so import pandas as pd and also
2:37
we need to import the numpy package as
2:40
np and then we need to set how many rows
2:43
of data that you want to generate so I
2:45
will set this to 100 and then this
2:48
pandas library contains a function here
2:51
which is data
2:53
frame and inside this we pass the set of
2:57
columns that we want to generate so we
3:00
need to
3:00
generate the names 100 names so here
3:05
we'll be looping
3:07
through using the for
3:16
loop so we'll be using a for loop here
3:19
for i
3:20
in looping through 1 to 100 so rows +
3:25
one
3:25
so similarly we'll be doing it for age
3:29
column as well so for this we'll be
3:33
using the nump numpy package to generate
3:37
the random set of data so we have a set
3:40
of methods here so for generating random
3:42
integer we have this
3:45
method 8 to 60 and size is equal to
3:50
rows similarly you'll be having the
3:53
third column here the country column
3:57
and so here you can set a predefined
4:01
choices here what countries that you
4:04
want
4:05
to put here so it will be selecting
4:08
these countries for each record here so
4:12
we have set these five countries here so
4:14
it will select every time from here
4:19
then we lastly we have the marks column
4:21
here right here so once again you'll be
4:24
generating a
4:32
integer 40 to 100 and then we set the
4:36
size to
4:42
rows so that's all after setting this it
4:45
now becomes easy so we can upon this
4:48
data frame we can call a set of methods
4:50
first of all for exporting this data to
4:53
CSV we can set
4:56
this data dot CSV and
5:01
index then we also have the method to
5:05
Excel for generating it as a Excel
5:11
file and lastly we also have the method
5:16
to_json for exporting this data to
5:25
JSON we can even set the indentation
5:28
right here which is
5:31
four so this completes the script a very
5:34
simple package you first of all import
5:36
this you set the number of rows to be
5:39
generated so we set this to 100 and then
5:41
we generate provide the schema provide
5:44
the column names and then we export this
5:46
data to all the formats
5:49
so you can see that it will generate the
5:52
data here in all the three formats you
5:54
will see
5:57
that so if I set this to uh rows to 10
6:01
here so now it will only generate 10
6:03
rows of data
6:06
so this is a very useful script for
6:08
generating random set of data in various
6:10
formats here uh it will every time it
6:13
will be random and it will be quick so
6:17
all the script is given in the
6:18
description of the video and thank you
6:20
very much for watching this video and
6:22
also check out my website uh
6:25
freemediatoolshu.com uh which contains
6:28
thousands of tools
