I was searching for a particular file which contains specific random data to be used in one of the online training for my data science course. The instructor forgot to provide the data file but I only had the label of data with me.
After searching on net for that particular file, idea came in my mind to use Microsoft copilot AI to generate a csv file with the labels I have using Python.
Therefore I used the following prompt on CoPilot to generate me the python code to run.
AI Prompt:
"please create a python code which can generate a csv file which contains following labelled data with 100 rows of random details. first name, last name, place of birth, current address, post code, kids, email address."
Python Code:
import csv
import random
import faker
# Initialize Faker library
fake = faker.Faker()
# Generate 100 rows of random data
data = []
for _ in range(100):
first_name = fake.first_name()
last_name = fake.last_name()
place_of_birth = fake.city()
current_address = fake.address()
post_code = fake.zipcode()
kids = random.randint(0, 5)
email = fake.email()
data.append([first_name, last_name, place_of_birth, current_address, post_code, kids, email])
# Write data to a CSV file
with open('random_data.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(['First Name', 'Last Name', 'Place of Birth', 'Current Address', 'Post Code', 'Kids', 'Email Address'])
writer.writerows(data)
print("CSV file 'random_data.csv' created successfully!")
Make sure you have the faker
library installed (pip install faker
) before running this code. It will create a CSV file named “random_data.csv” in the same directory as your Python script. Feel free to adjust the data fields or customize the code as needed!