chatgpt: Create fake data for your application and skip learning a library to do t

One very common task i have is to create fake data to test an application, for example we might need a csv file with name, last name , age…

chatgpt: Create fake data for your application and skip learning a library to do t
Photo by DeepMind on Unsplash

chatgpt: Create test data for your application and skip learning a library to do this!

One very common task i have is to create test data to test an application, for example we might need a csv file with name, last name , age and other data, There are many libraries to do this but lets see how we can do the same task using chatgpt, the main advantage of using chatgpt for such tasks is that you eliminate the need to learn a new library which can be time consuming.

In order to perform the test you will need to create a Python script that will query chatgpt or to ask chatgpt from the web site, but you can also try a command like tool i have create for such tasks

kpatronas/shellgpt: Query chatgpt from your shell (github.com)

Its a very handy shell script that with minimal configuration you can ask chatgpt from the command line prompt like this.

$ chatgpt -p "Tell me a joke" 
Q: What did the fish say when it hit the wall? 
A: Dam!

How we can generate test data with chatgpt

When dealing with chatgpt queries you must be very precice on what you ask because the same question can vary from run to run

For example i asked for “Create a table with 5 rows having headers name,last-name,age,gender with random values”, the result is correct but it added the “|” character as a separator, which is not a mistake since we didn’t mention the separator.

chatgpt -p "Create a table with 5 having headers name,last-name,age,gender with random values" 
Name | Last-Name | Age | Gender 
-----|-----------|-----|------- 
John | Smith | 25 | Male 
Jane | Doe | 32 | Female 
Bob | Johnson | 28 | Male 
Sara | Miller | 22 | Female 
Alex | Williams | 30 | Male

Being more precise gives consistent results

chatgpt -p "Create a table with 20 having headers name,last-name,age,gender with random values, comma separated." 
Name,Last-Name,Age,Gender 
John,Smith,25,Male 
Jane,Doe,30,Female 
Michael,Williams,45,Male 
Emily,Jones,35,Female 
Jacob,Brown,20,Male 
Sophia,Davis,27,Female 
Joshua,Miller,40,Male 
Emma,Wilson,32,Female 
Matthew,Taylor,22,Male 
Olivia,Anderson,24,Female 
Daniel,Thomas,50,Male 
Ava,Jackson,28,Female 
Christopher,White,38,Male 
Isabella,Harris,31,Female 
Andrew,Martin,23,Female 
Mia,Thompson,26,Female 
Anthony,Garcia,41,Male 
Abigail,Martinez,29,Female 
David,Robinson,48,Male 
Elizabeth,Clark,33,Female

We can even fine tune parameters for example the number of males vs females

$ chatgpt -p "Create a table with 20 rows having headers name,last-name,age,gender with random values, comma separated. with 15 males and 5 females" 
Name,Last-Name,Age,Gender 
John,Smith,25,Male 
James,Johnson,30,Male 
Michael,Williams,35,Male 
David,Jones,40,Male 
Robert,Brown,45,Male 
Mark,Davis,50,Male 
Steven,Miller,55,Male 
Joseph,Wilson,60,Male 
Charles,Moore,65,Male 
Christopher,Taylor,70,Male 
Daniel,Anderson,75,Male 
Paul,Thomas,80,Male 
Richard,Jackson,85,Male 
Brian,White,90,Male 
Kevin,Harris,95,Male 
Jason,Martin,20,Male 
Jeffrey,Thompson,25,Male 
Anthony,Garcia,30,Male 
Mary,Martinez,35,Female 
Patricia,Robinson,40,Female 
Linda,Clark,45,Female 
Barbara,Rodriguez,50,Female 
Jennifer,Lewis,55,Female

conclusion

chatgpt might probably will not replace developers and engineers of any kind any time soon, but its a valuable tool that can help us to accomplish tasks that will take a lot of time by learning a library.

Join Medium with my referral link - Konstantinos Patronas
As a Medium member, a portion of your membership fee goes to writers you read, and you get full access to every story…