Python: How to convert a large zipped csv file to a dictionary? -
i had following code working convert csv file dictionary.
with open(filename, encoding='utf-8') file: dictreader = csv.dictreader(file) row in dictreader: #do work
these csv files arrive zipped , figured i'd attempt modify code read zipped csv files dictionary. things tricky since understand it, when opening file inside zip archive, file opened bytes rather text. had working reading entire file in, , converting text, hit large file , had memory error. updated code read file in 1 line @ time , suspect i'll have build dictionary manually, figured worth asking here.
thanks pmsh.93, have working.
with zipfile.zipfile(filename) zipfile: fname in zipfile.infolist(): zipfile.open(fname) file: file = io.textiowrapper(file, encoding="utf-8") row in csv.dictreader(file): #do work
Comments
Post a Comment