Python Read CSV File Specific Column Example

By Hardik Savani October 30, 2023 Category : Python

Hello Guys,

I am going to explain to you example of python read csv file specific column. If you have a question about python read csv file column name then I will give a simple example with a solution. Here you will learn how to get specific row data from csv file in python. I explained simply step by step python read csv file specific column data.

In this example, we will take one demo.csv file with ID, Name and Email columns. Then, we will use open() and DictReader() functions to read specific column data from csv file.

I will give you one example for reading csv file specific column data in python, so Without any further ado, let's see below code example:

You can use these examples with python3 (Python 3) version.

Example 1:

from csv import reader
from csv import DictReader
# open demo.csv file in read mode
with open('demo.csv', 'r') as readObj:
    # Pass the file object to DictReader() to get the DictReader object
    csvDictReader = DictReader(readObj)
    # get over each line as a ordered dictionary
    for row in csvDictReader:
        # Get ID and Name Columns only from CSV File
        print(row['ID'], row['Name'])


1 Hardik Savani
2 Vimal Kashiyani
3 Harshad Pathak

I hope it can help you...

Tags :