Pandas has some learning curve, but once you are comfortable with them, you will love them. See one simple solution to your problem. Cheers.

import pandas as pd
import matplotlib.pyplot as plt
from datetime import timedelta

df = pd.read_csv(r"your-folder\dates.csv", parse_dates=[0]) # assuming dates are in the first column
df.sort_values(by="date", ascending=False, inplace=True)
last_date = df["date"].max().date()
start_date = df["date"].max().date() - timedelta(days=365)
dfRange = df[(df["date"].dt.date >= start_date) & (df["date"].dt.date <= last_date)]

plt.scatter(dfRange["txCount"],dfRange["txVolume(USD)"])
plt.xlabel("txCount")
plt.ylabel("txVolume(USD)")
plt.savefig(r"target-location\dates.png")
plt.close()
Answer from griggy on Stack Overflow
Discussions

python csv to dictionary using csv or pandas module - Stack Overflow
I am using Python's csv.DictReader to read in values from a CSV file to create a dictionary where keys are first row or headers in the CSV and other rows are values. It works perfectly as expected ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - Does csv.DicReader() return a dictionary object? - Stack Overflow
If you look to store for calculations than will suggest to look for pandas dataframe instead of dict ... ... Given your desired output, you do not need to use dict or, consequently, csv.DictReader. Instead, just use csv.reader, which returns an iterator. More on stackoverflow.com
๐ŸŒ stackoverflow.com
python - Load csv file as a dataframe - Stack Overflow
This is a noob question, but without using Pandas (pd.read) how can I import a CSV file and load it to a DataFrame object so I can call it (e.g. print (loaded_file) ) and print the contents of the ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
May 24, 2017
python - How to use csv.DictReader - Stack Overflow
I am doing a program for a class, and our teacher gave us the csv.DictReader function to use, without explaining it. It is just part of a larger program. I am trying to read a spreadsheet of weat... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Medium
medium.com โ€บ @3valuedlogic โ€บ using-python-csv-3-dictreader-e4814ce2e44
Using Python CSV #3 โ€” DictReader. Pythonโ€™s csv module allows you to workโ€ฆ | by David W. Agler | Medium
December 22, 2022 - Using Python CSV #3 โ€” DictReader Pythonโ€™s csv module allows you to work with csv files (e.g., Excel spreadsheets). In previous articles (#1 and #2), I looked at two functions of thecsv module โ€ฆ
Top answer
1 of 2
2

csv.reader

Given your desired output, you do not need to use dict or, consequently, csv.DictReader. Instead, just use csv.reader, which returns an iterator. Then use next and list to extract headers and data respectively:

from io import StringIO
import csv

x = StringIO("""play,weather,temperature
yes,sunny,77
no,rainy,60
yes,windy,70""")

# replace x with open('file.csv', 'r')
with x as fin:
    reader = csv.reader(fin)
    headers = next(reader)  # get headers from first row
    data = list(reader)     # exhaust iterator from second row onwards

The result is a list of headers, and a list of lists for data:

print(headers)

['play', 'weather', 'temperature']

print(data)

[['yes', 'sunny', '77'],
 ['no', 'rainy', '60'],
 ['yes', 'windy', '70']]

pandas

If you are willing to use a 3rd party library, Pandas may be a better option as it handles type conversion and indexing more conveniently:

import pandas as pd

df = pd.read_csv('file.csv')

The result is a pd.DataFrame object:

print(df)

  play weather  temperature
0  yes   sunny           77
1   no   rainy           60
2  yes   windy           70

print(type(df))

<class 'pandas.core.frame.DataFrame'>
2 of 2
1

DictReader returns a file-like object. It still reads the data from the csv file in one row at a time, but the returned rows are ordered dictionaries instead of lists.

If your files is:

play,weather,temperature
yes,sunny,77
no,rainny,60
yes,windy,70

Then you can use DictReader in the following way:

with open('path/to/file.csv') as fp:
    header = fp.readline().strip().split(',')
    dreader = DictReader(fp, header)
    data = list(dreader)

In this case, data will be a list of OrderedDict objects with the mapping from the headers to each item in the row.

data
#returns:
[OrderedDict([('play', 'yes'), ('weather', 'sunny'), ('temperature', '77')]),
 OrderedDict([('play', 'no'), ('weather', 'rainny'), ('temperature', '60')]),
 OrderedDict([('play', 'yes'), ('weather', 'windy'), ('temperature', '70')])]
๐ŸŒ
Saturn Cloud
saturncloud.io โ€บ blog โ€บ how-to-convert-a-csv-file-to-a-dictionary-in-python-using-the-csv-and-pandas-modules
How to Convert a CSV File to a Dictionary in Python using the CSV and Pandas Modules | Saturn Cloud Blog
May 1, 2026 - In this example, we import the Pandas module using the import statement. We then use the read_csv() function to read the CSV file data.csv into a Pandas DataFrame data.
Find elsewhere
๐ŸŒ
Wordpress
statcompute.wordpress.com โ€บ 2018 โ€บ 10 โ€บ 21 โ€บ import-csv-as-dictionary-list
Import CSV as Dictionary List โ€“ Yet Another Blog in Statistical Computing
October 22, 2018 - from csv import DictReader from pprint import pprint ### EXAMINE 3 ROWS OF DATA with open("Downloads/nycflights.csv") as f: d = DictReader(f) l = [next(d) for i in xrange(3)] pprint(l[0]) #{'air_time': '227', # 'arr_delay': '11', # 'arr_time': '830', # 'carrier': 'UA', # 'day': '1', # 'dep_delay': '2', # 'dep_time': '517', # 'dest': 'IAH', # 'distance': '1400', # 'flight': '1545', # 'hour': '5', # 'minute': '17', # 'month': '1', # 'origin': 'EWR', # 'tailnum': 'N14228', # 'year': '2013'} A solution to address the aforementioned issue is first to import the csv file into a Pandas DataFrame and then to convert the DataFrame to the list of dictionaries, as shown in the code snippet below.
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ 5 best ways to convert csv to dataframe in python
5 Best Ways to Convert CSV to DataFrame in Python - Be on the Right Side of Change
March 1, 2024 - You can use Pythonโ€™s csv module in conjunction with pandas to read a CSV file into a DataFrame. This is a bit more manual but gives you the opportunity to handle the data at a lower level before creating a DataFrame. ... import csv import pandas as pd with open('data.csv', 'r') as csvfile: reader = csv.DictReader(csvfile) data = list(reader) df = pd.DataFrame(data) print(df)
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ csv.html
csv โ€” CSV File Reading and Writing
The csv moduleโ€™s reader and writer objects read and write sequences. Programmers can also read and write data in dictionary form using the DictReader and DictWriter classes. ... The Python Enhancement Proposal which proposed this addition to Python.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ pandas โ€บ using-csv-module-to-read-the-data-in-pandas
Using csv module to read the data in Pandas - GeeksforGeeks
August 5, 2021 - For that purpose, we will use Python's csv library to read and write tabular data in CSV format. For link to the CSV file used in the code click here. Code #1: We will use csv.DictReader() function to import the data file into the Python's ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ working-csv-files-python
Working with csv files in Python - GeeksforGeeks
We can use Pandas to write CSV files. It can done by using pd.DataFrame() function. In this example, the Pandas library is used to convert a list of dictionaries (mydict) into a DataFrame, representing tabular data.
Published ย  August 5, 2025
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 41155239 โ€บ how-to-use-csv-dictreader โ€บ 41155479
python - How to use csv.DictReader - Stack Overflow
import csv def read_file(filename, col_list): with open(filename, 'r') as f: reader = csv.DictReader(f) final_dict = { col_name: [] for col_name in col_list } for row in reader: for col_name in col_list: final_dict[col_name].append(row[col_name]) ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ load-csv-data-into-list-and-dictionary-using-python
Load CSV data into List and Dictionary using Python - GeeksforGeeks
July 12, 2025 - CSV raw data is not utilizable in order to use that in our Python program it can be more beneficial if we could read and separate commas and store them in a data structure. We can convert data into lists or dictionaries or a combination of both either by using functions csv.reader and csv.dictreader ...
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ when using reader or dictreader from the csv module, why do you need to access the return value while the file is still open?
r/learnpython on Reddit: When using reader or DictReader from the csv module, why do you need to access the return value while the file is still open?
August 7, 2023 -

Ok, this will make more sense. Why does this work:

import csv

with open('test.csv') as csv_file:
    csv_reader = csv.DictReader(csv_file)
    for row in csv_reader:
        print(row)

But this gives an error that the file is closed:

import csv

with open('test.csv') as csv_file:
    csv_reader = csv.DictReader(csv_file)

for row in csv_reader:
    print(row)

Traceback (most recent call last):
File "c:\Users\John\Documents\Python\test_project\test2.py", line 5, in <module> for row in csv_reader: File "C:\Users\John\AppData\Local\Programs\Python\Python311\Lib\csv.py", line 110, in next self.fieldnames File "C:\Users\John\AppData\Local\Programs\Python\Python311\Lib\csv.py", line 97, in fieldnames self._fieldnames = next(self.reader) ^ 
ValueError: I/O operation on closed file.

Does DictReader (and also reader) not just run once and return a value? Why is csv_file being accessed after the line it's used in?

Thanks!

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ pandas โ€บ reading-csv-files-in-python
Reading CSV files in Python - GeeksforGeeks
May 25, 2026 - ... CSV column names become dictionary keys and each row stores values corresponding to those keys. The read_csv() function from the pandas library reads the CSV file and stores the data in a DataFrame...
Top answer
1 of 4
9

You could use a library like pandas, it will infer the types for you (it's a bit of an overkill but it does the job).

import pandas
data = pandas.read_csv(r'..\data\data.csv')
# if you just want to retrieve the first column as a list of int do
list(data.Col1)
>>> [1, 90]

# to convert the whole CSV file to a list of dict use
data.transpose().to_dict().values()
>>> [{' Col2': 2, ' Col3': 3, 'Col1': 1}, {' Col2': 2, ' Col3': 3, 'Col1': 90}]

Alternatively here is an implementation of a typed DictReader:

from csv import DictReader
from itertools import imap, izip

class TypedDictReader(DictReader):
  def __init__(self, f, fieldnames=None, restkey=None, restval=None, \
      dialect="excel", fieldtypes=None, *args, **kwds):

    DictReader.__init__(self, f, fieldnames, restkey, restval, dialect, *args, **kwds)
    self._fieldtypes = fieldtypes

  def next(self):
    d = DictReader.next(self)
    if len(self._fieldtypes) >= len(d) :
      # extract the values in the same order as the csv header
      ivalues = imap(d.get, self._fieldnames) 
      # apply type conversions
      iconverted = (x(y) for (x,y) in izip(self._fieldtypes, ivalues)) 
      # pass the field names and the converted values to the dict constructor
      d = dict(izip(self._fieldnames, iconverted)) 

    return d

and here is how to use it:

reader = TypedDictReader(open('..\data\data.csv'), dialect='excel', \
  fieldtypes=[int, int, int])
list(reader)
>>> [{' Col2': 2, ' Col3': 3, 'Col1': 1}, {' Col2': 2, ' Col3': 3, 'Col1': 90}]
2 of 4
6

If you quote the non-numeric values in the csv file and initialize the reader by

pol = csv.DictReader(open('..\data\data.csv'),
    quoting=csv.QUOTE_NONNUMERIC, dialect="excel")

then numeric values will be automatically converted to floats.

๐ŸŒ
DEV Community
dev.to โ€บ bowmanjd โ€บ flexible-csv-handling-in-python-with-dictreader-and-dictwriter-3hae
Flexible CSV Handling in Python with DictReader and DictWriter - DEV Community
February 9, 2026 - CSV files are often used as a vehicle to carry large simple tables of data. Python has built-in CSV handling capability. In this article, we will explore a flexible way of reading and saving CSV files using Python's csv.DictReader and csv.DictWriter.