ItSolutionStuff.com

Python Read CSV File Specific Column Example

By Hardik Savani • October 30, 2023
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:

main.py

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'])

Output:

1 Hardik Savani
2 Vimal Kashiyani
3 Harshad Pathak

I hope it can help you...

Tags: Python
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Python Read CSV File Line by Line Example

Read Now →

Python Read CSV File Without Header Example

Read Now →

How to Read a CSV File in Python?

Read Now →

How to Write CSV File in Python?

Read Now →

How to Add Header in CSV File using Python?

Read Now →

How to Write Multiple Rows in CSV using Python?

Read Now →

How to Read Text File Line by Line in Python?

Read Now →

How to Append Text or Lines to a Text File in Python?

Read Now →

Python List Add Element at Beginning Example

Read Now →

How to Get Unique Elements from List in Python?

Read Now →

Python Get First Date of Next Month Example

Read Now →

Python Create Zip Archive from Directory Example

Read Now →