Ran a loop that counted the number of rows of all .csv files in a folder. I now need to save these results to a dictionary.
import os
for filename in os.listdir(path):
with open(filename, 'r', encoding="latin-1") as fileObj:
if filename.endswith('csv'):
print('Rows counted {} in the csv {}'.format(len(fileObj.readlines()) -1, filename))
I get an output of what I want, but any way I try to save it to a dict results in "I/0 operation closed on file." (I am relatively new sorry if this is a dumb question)
Blockquote
Output:
Rows counted 840593 in the csv MA_2019_01.csv
Rows counted 818861 in the csv MA_2019_02.csv
Rows counted 914653 in the csv MA_2019_03.csv
Rows counted 1011374 in the csv MA_2019_04.csv
Rows counted 1088294 in the csv MA_2019_05.csv
Rows counted 1120696 in the csv MA_2019_06.csv
Rows counted 1119932 in the csv MA_2019_07.csv
Rows counted 1194284 in the csv MAg_2019_08.csv
Rows counted 1136953 in the csv MA_2019_09.csv
Rows counted 1010777 in the csv MA_2019_10.csv
Rows counted 901468 in the csv MA_2019_11.csv
Rows counted 950661 in the csv MA_2019_12.csv