How to Write Multiple Rows in CSV using Python?
Hello, all! In this article, we will talk about how to write multiple rows in csv using python. you will learn python csv files multiple rows example. In this article, we will implement a python write multiple rows to csv file. In this article, we will implement a write multiple lines to csv file python. Follow the below tutorial step of python list to csv rows.
In this example, we will create demo.csv file with ID, Name and Email fields. we will create "data" list with values for write multiple rows to csv file. we will use open(), writer(), writerow(), writerows() and close() functions to create csv file from list.
writerows(): it will write multiple rows with list.
So, Without any further ado, let's see below code example:
You can use these examples with python3 (Python 3) version.
import csv # open the file in the write mode f = open('demo.csv', 'w') # create the csv writer writer = csv.writer(f) header = ['ID', 'Name', 'Email'] data = [ [1, 'Hardik Savani', 'email@example.com'], [2, 'Vimal Kashiyani', 'firstname.lastname@example.org'], [3, 'Harshad Pathak', 'email@example.com'], ] # write the header writer.writerow(header) # write a row to the csv file writer.writerows(data) # close the file f.close()
You can see csv file layout:
I hope it can help you...
We are Recommending you
- How to Create CSV File in Python?
- Python Read Text File into List Example
- How to Read Text File Line by Line in Python?
- How to Read a Text File in Python?
- How to Append Text or Lines to a Text File in Python?
- Python Generate Text File from List Example
- Python Create Text File If Not Exists Example
- How to Capitalize String in Python?
- Python Create an Empty Text File Example
- How to Find Average of List in Python?
- How to Get Min Value from Python List?
- How to Get Current Date and Time in Python?