The easiest way is to just set:

reader.fieldnames = "email", "name", "id",  "phone"

You can save the old fieldnames if you want too.

Answer from jamylak on Stack Overflow
🌐
Python
docs.python.org › 3 › library › csv.html
csv — CSV File Reading and Writing
If the argument passed to fieldnames is an iterator, it will be coerced to a list. Changed in version 3.6: Returned rows are now of type OrderedDict. Changed in version 3.8: Returned rows are now of type dict. ... >>> import csv >>> with open('names.csv', newline='') as csvfile: ... reader = csv.DictReader(csvfile) ...
Discussions

python - Reading column names alone in a csv file - Stack Overflow
When I "upgraded" to python3 the fieldnames property now returns None. According to the docs it looks like it should still work, but it doesn't. For what it's worth. I'm using python 3.7. I think there was a change in what the DictReader returns in python3.6. 2019-07-07T23:20:26.38Z+00:00 ... Interesting - for what it's worth, a hello world CSV ... More on stackoverflow.com
🌐 stackoverflow.com
python - Read CSV items with column name - Stack Overflow
... If the fieldnames parameter is omitted, the values in the first row of the csvfile will be used as the fieldnames. ... Sign up to request clarification or add additional context in comments. ... You can use a csv.DictReader instance to get this behaviour. More on stackoverflow.com
🌐 stackoverflow.com
What's the type of csv.Dictreader.fieldnames in python? - Stack Overflow
I am trying to read a csv file and read the field names (top row of csv file) from it. I used csv.Dictreader to create a reader object and extracted the top row using the reader.fieldnames object. ... More on stackoverflow.com
🌐 stackoverflow.com
csv.DictReader.fieldnames should be Optional[Sequence[str]]
csv.DictReader.fieldnames defaults to None, and gets set by reading the first line of data. However if there is no first line of data it remains None. Since fieldnames is not marked as Optional cod... More on github.com
🌐 github.com
1
February 4, 2020
People also ask

Should I use csv.DictReader or pandas for CSV files?
Use stdlib csv.DictReader for streaming large files, simple ETL, and scripts where you want zero dependencies and constant memory. Use pandas.read_csv when you need filtering, grouping, joins, or numeric analysis and can fit the data in memory. For case-insensitive headers in pandas, normalize the columns with df.columns.str.strip().str.lower().
🌐
micropyramid.com
micropyramid.com › home › blog › python › case-insensitive csv.dictreader in python
Case-Insensitive csv.DictReader in Python | MicroPyramid
Does csv.DictReader preserve column order?
Yes. csv.DictReader returns each row as a regular dict, and Python dictionaries have preserved insertion order since Python 3.7, so columns appear in the same order as the header. Older code that relied on OrderedDict rows is obsolete; a plain dict already keeps the order.
🌐
micropyramid.com
micropyramid.com › home › blog › python › case-insensitive csv.dictreader in python
Case-Insensitive csv.DictReader in Python | MicroPyramid
Why does csv.DictReader raise a KeyError on my header?
DictReader uses the exact text of the first row as dictionary keys. If the file says TITLE or Title but you look up row["Title"], the strings do not match and Python raises KeyError. Files exported from Excel can also prepend a UTF-8 BOM, turning the first header into \ufeffTitle. Normalizing the field names fixes all of these at once.
🌐
micropyramid.com
micropyramid.com › home › blog › python › case-insensitive csv.dictreader in python
Case-Insensitive csv.DictReader in Python | MicroPyramid
🌐
Medium
medium.com › @3valuedlogic › using-python-csv-3-dictreader-e4814ce2e44
Using Python CSV #3 — DictReader
December 22, 2022 - Fieldnames are either explicitly specified or are the first row of the csv. Our fieldnames should be the first row (the header): ‘name’, ‘age’, and ‘account’. These should map to the name, age, and account size of each person.
🌐
Vertabelo Academy
academy.vertabelo.com › course › python-csv › reading › reading › importing-csv-contents-using-custom-field-names
Read and Write CSV in Python | Learn Python | Vertabelo Academy
import csv with open('departments.csv') as csv_file: csv_reader = csv.DictReader(csv_file, fieldnames=['Department Name', 'Number of Employees', 'Department Budget']) line_count = 0 for row in csv_reader: if line_count > 0 and float(row['Department ...
🌐
Python Pool
pythonpool.com › home › blog › csv dicteader doesn’t have to be hard
CSV Dicteader Doesn't Have To Be Hard - Python Pool
December 18, 2021 - import csv class InsensitiveDictReader(csv.DictReader): # This class overrides the csv.fieldnames property, which converts all fieldnames without leading and trailing spaces and to lower case.
🌐
Runebook.dev
runebook.dev › en › docs › python › library › csv › csv.DictReader.fieldnames
Python CSV Headers: The Complete Guide to csv.DictReader.fieldnames
When you use csv.DictReader, it ... field names (column headers) and the values are the row's data. The .fieldnames attribute simply holds a list of these header strings, in the order they appear in the CSV file....
Find elsewhere
🌐
HotExamples
python.hotexamples.com › examples › csv › DictReader › fieldnames › python-dictreader-fieldnames-method-examples.html
Python DictReader.fieldnames Examples, csv.DictReader.fieldnames Python Examples - HotExamples
def load_data(uri, dateFormat): logging.info('loading data; uri: {0}'.format(uri)) from urllib2 import urlopen from csv import DictReader reader = DictReader(urlopen(uri).readlines()) encodedFieldNames = [] for fieldname in reader.fieldnames: encodedFieldNames.append(fieldname.decode("utf-8-sig").encode("utf-8")) reader.fieldnames = encodedFieldNames data = [] from time import strptime for row in reader: data.append({ 'date': strptime(row['Date'], dateFormat), 'open': float(row['Open']), 'close': float(row['Close']), 'high': float(row['High']), 'low': float(row['Low']), 'volume': float(row['Volume']) }) return data
Top answer
1 of 10
155

Though you already have an accepted answer, I figured I'd add this for anyone else interested in a different solution-

  • The csv module's DictReader object has a public attribute called fieldnames (as of Python 2.6 and above). https://docs.python.org/3.4/library/csv.html#csv.csvreader.fieldnames

An implementation could be as follows:

import csv

with open('C:/mypath/to/csvfile.csv', 'r') as f:
    dict_reader = csv.DictReader(f)

    #get header fieldnames from DictReader and store in list
    headers = dict_reader.fieldnames

    #sample file reading logic
    for line in dict_reader:
        print(line[headers[0]])
        

In the above, dict_reader.fieldnames returns a list of your headers (assuming the headers are in the top row). Which allows...

>>> print(headers)
['MyColumn1', 'MyColumn2', 'MyColumn3']

If your headers are in, say the 2nd row (with the very top row being row 1), you could do as follows:

import csv

with open('C:/mypath/to/csvfile.csv', 'r') as f:
    #you can eat the first line before creating DictReader.
    #if no "fieldnames" param is passed into
    #DictReader object upon creation, DictReader
    #will read the upper-most line as the headers
    f.readline()
    
    dict_reader = csv.DictReader(f)
    headers = dict_reader.fieldnames

    #sample file reading logic
    for line in dict_reader:
        print(line[headers[0]])
2 of 10
85

You can read the header by using the next() function which return the next row of the reader’s iterable object as a list. then you can add the content of the file to a list.

import csv
with open("C:/path/to/.filecsv", "rb") as f:
    reader = csv.reader(f)
    i = reader.next()
    rest = list(reader)

Now i has the column's names as a list.

print i
>>>['id', 'name', 'age', 'sex']

Also note that reader.next() does not work in python 3. Instead use the the inbuilt next() to get the first line of the csv immediately after reading like so:

import csv
with open("C:/path/to/.filecsv", "rb") as f:
    reader = csv.reader(f)
    i = next(reader)

    print(i)
    >>>['id', 'name', 'age', 'sex']
🌐
MicroPyramid
micropyramid.com › home › blog › python › case-insensitive csv.dictreader in python
Case-Insensitive csv.DictReader in Python | MicroPyramid
July 30, 2018 - Because DictReader builds each row from self.fieldnames, overriding this single property is enough. Rows come back as ordinary dicts keyed by the normalized header, so row["title"] works regardless of how "Title", " TITLE ", or "title" was written in the source file. """ @property def fieldnames(self): names = super().fieldnames if names is None: return None return [name.strip().lower() for name in names]
🌐
CodeRivers
coderivers.org › blog › python-csv-dictreader
Python `csv.DictReader`: A Comprehensive Guide - CodeRivers
February 22, 2026 - If your CSV file does not have a header row, you can specify the column names yourself. import csv with open('no_header.csv', mode='r', encoding='utf-8') as csv_file: fieldnames = ['col1', 'col2', 'col3'] csv_reader = csv.DictReader(csv_file, fieldnames=fieldnames) next(csv_reader) # Skip the ...
🌐
Brodan
brodan.biz › blog › parsing-csv-files-with-python
Parsing CSV Files with Python's DictReader - Brodan.biz
August 24, 2018 - The columns in each subsequent ... does not contain your column names, you can pass a fieldnames parameter into the DictReader's constructor to assign the dictionary keys manually....
🌐
GitHub
github.com › python › typeshed › issues › 3713
csv.DictReader.fieldnames should be Optional[Sequence[str]] · Issue #3713 · python/typeshed
February 4, 2020 - csv.DictReader.fieldnames defaults to None, and gets set by reading the first line of data. However if there is no first line of data it remains None. Since fieldnames is not marked as Optional cod...
Author   python
🌐
GeeksforGeeks
geeksforgeeks.org › get-column-names-from-csv-using-python
Get column names from CSV using Python - GeeksforGeeks
April 7, 2025 - import csv with open('data.csv') as csv_file: csv_reader = csv.DictReader(csv_file) header = list(dict(next(csv_reader)).keys()) print("List of column names:", header)
🌐
ZetCode
zetcode.com › python › csv
Python CSV - read, write CSV in Python
January 29, 2024 - The csv.DictReader class operates like a regular reader but maps the information read into a dictionary. The keys for the dictionary can be passed in with the fieldnames parameter or inferred from the first row of the CSV file.
🌐
Codecademy Forums
discuss.codecademy.com › data science
What does .dictreader() do? - Data Science - Codecademy Forums
September 27, 2023 - hi guys! I have a question. I know when we use .dictreader() we use csv module to make a dictionary out of the csv file, so it’s easier to use for programming, but I don’t get it how does this dictionary look like exactly. first, I thought it uses titles in the first line to make keys, and then unzip the rest into these keys based on their index. but now, I see it like this, which doesn’t make sense. import csv with open("cool_csv.csv") as cool_csv_file : cool_csv_dict = csv.DictReader(coo...
🌐
Jython
jython.org › jython-old-sites › docs › library › csv.html
13.1. csv — CSV File Reading and Writing — Jython v2.5.2 documentation
class class csv.DictReader(csvfile[, fieldnames=None[, restkey=None[, restval=None[, dialect=’excel’[, *args, **kwds]]]]])