Python | Generate Personalized Data from given list of expressions

Given different lists of expressions, the task is to generate a random combination of these expressions in a csv file for some purposes such as test databases contrary to ordinal data simulator which generates datasets from random numbers and standard names.

Examples:

Input :lists of your own expressions 
Names   = ['David', 'Emilia', 'John', 'Karmen'], 
Hobbies = ['Hiking', 'football', 'Gaming', 'Skydiving'],
skills  = ['Communication', 'leadership', 'cooking']
 
Output : a csv file with a random combination of expressions
Names, Age, Hobbies, skills
Emilia, 54, "['football', 'Hiking']", leadership
David, 22, "['Skydiving', 'Gaming']", cooking
Emilia, 59, "['football', 'Skydiving']", leadership
Emilia, 45, "['Gaming', 'football']", leadership
David, 62, "['Hiking', 'football']", cooking
David, 56, "['football', 'Hiking']", leadership
John, 17, "['Gaming', 'football']", cooking
David, 28, "['Gaming', 'football']", leadership
David, 28, "['Skydiving', 'football']", cooking
John, 17, "['Gaming', 'Skydiving']", cooking
John, 61, "['Hiking', 'football']", cooking
John, 44, "['Hiking', 'Gaming']", leadership
Emilia, 17, "['Hiking', 'Gaming']", Communication
Karmen, 34, "['football', 'Skydiving']", leadership
Emilia, 65, "['football', 'Hiking']", leadership

Code : Generating Personalised Data

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing libraries
import csv
import random
  
# create a csv file named "abc" that contains our dataset
with open('abc.csv', 'w', newline ='') as f: 
    file = csv.writer(f)
    file.writerow(['Names', 'Age', 'Hobbies', 'skills'])
      
    # generate rows as much as wanted
    for i in range (1, 10) :                          
        Names =['David', 'Emilia', 'John', 'Karmen']
        Hobbies =['Hiking', 'football', 'Gaming', 'Skydiving']
        skills =['Communication', 'leadership', 'cooking']
        file.writerow([random.choice(Names), random.randint(17, 65), 
                       random.sample(Hobbies, 2), random.choice(skills)])

chevron_right




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

2


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.