In this tutorial, I will explain how to create CSV and store random numbers in python.
In any scraping task, you have to store information into a CSV file to store the data.
Step 1: Install CSV
You have to install CSV into your python so open your terminal and put the below command.
pip install python-csv
Step 2: Install Random Package
In this step, you have to install a python random package to generate a new random number and store it into a newly generated CSV file.
pip install random2
Here you can create your script for generating a new CSV file.
import csv import random randomNumber = open('test.csv', 'w+') try: writer = csv.writer(randomNumber) writer.writerow(('ID', 'Value')) for i in range(10): writer.writerow((i+1,random.randint(1, 1000))) finally: randomNumber.close()
I hope it will help you.