Read data from csv with python3

It’s common that we need to process data in csv format.

We will use the csv library to read csv file. Here is a sample code for read data from csv file and print each row.

import csv
from argparse import ArgumentParser

# Argument Parser setup
parser = ArgumentParser(description="Simple csv file reader")
parser.add_argument("--infile", help="Input CSV file", required=True)

args = parser.parse_args()


with open(csv_file, "r") as file:
    reader = csv.reader(file)
    for row in reader:
        print(row)

Leave a comment

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