How to use CSV Module In Python
In this example, we are using the csv module in Python to open and read a CSV file named ‘data.csv‘. We skip the header row using next(reader, None) and then loop through each row in the CSV file. We check if the first column of each row matches ‘ReactJS‘ and if it does, we print the corresponding description of ReactJS from the second column.
import csv
with open('data.csv', newline='') as csvfile:
reader = csv.reader(csvfile)
next(reader, None)
for row in reader:
if row[0] == 'ReactJS':
print(f"Description of ReactJS: {row[1]}")
Output:
Description of ReactJS: JavaScript library for building user interfaces
Retrieve A Specific Element In a Csv File using Python
We have given a file and our task is to retrieve a specific element in a CSV file using Python. In this article, we will see some generally used methods for retrieving a specific element in a CSV file.