Create a new CSV for Random numbers in Python.

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+')
    writer = csv.writer(randomNumber)
    writer.writerow(('ID', 'Value'))
    for i in range(10):
        writer.writerow((i+1,random.randint(1, 1000)))

I hope it will help you.

About Dhaval Shah

My name is Dhaval Shah. I'm a Laravel developer. I live in India and I love to write tutorials and tips that can help other developers. I am a big fan of PHP, Java-script, JQuery, Laravel, WordPress, and Bootstrap.
Follow me on Github / Linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter
Enter your email to receive a weekly round-up of our best posts. Learn more!