Python Read CSV File Specific Column Example
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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Python Read CSV File Line by Line Example
- Python Read CSV File Without Header Example
- How to Read a CSV File in Python?
- How to Write CSV File in Python?
- How to Add Header in CSV File using Python?
- How to Write Multiple Rows in CSV using Python?
- How to Read Text File Line by Line in Python?
- How to Append Text or Lines to a Text File in Python?
- Python List Add Element at Beginning Example
- How to Get Unique Elements from List in Python?
- Python Get First Date of Next Month Example
- Python Create Zip Archive from Directory Example