samedi 10 août 2019

Finding the number of values greater than a particular value (using a csv file)

I have a csv file named 'datavalues.csv'. It has about 20,000 values and I am curious as to how many of those values are over 10,000.

#!/usr/bin/python

import csv

with open('datavalues.csv', 'rb') as datavalues:
  datavaluesreader = csv.reader(datavalues, delimiter=',')

print(sum(x >= 10000 for x in datavaluesreader))

I have the code below, but I keep getting the following error ValueError: I/O operation on closed file

Aucun commentaire:

Enregistrer un commentaire