How to Get Column Names from CSV File in Python?
This tutorial shows you python get column names from csv file. We will look at an example of how to get header from csv file in python. This article will give you a simple example of python csv get header names. If you have a question about how to get column names from csv file in python then I will give a simple example with a solution.
In this example, we will take one demo.csv file with ID, Name and Email fields. Then, we will use open(), next() and reader() functions to read header from csv file.
I will give you one example for reading csv file column names in python, so Without any further ado, let's see below code example:
You can use these examples with python3 (Python 3) version.
from csv import reader # skip first line from demo.csv with open('demo.csv', 'r') as readObj: csvReader = reader(readObj) # Get CSV File Columns Name header = next(csvReader) print(header)
['ID', 'Name', 'Email']
I hope it can help you...
We are Recommending you
- 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?
- Python Write CSV File from List Example
- Python Read Text File into List Example
- How to Read a Text File in Python?
- Python Generate Text File from List Example
- Python Post Request with Bearer Token Example
- Python Get First Date of Last Month Example
- How to Add Seconds to DateTime in Python?
- How to Add Minutes to DateTime in Python?
- Python PUT Request with Parameters Example