This should be simple but... I have a botched up csv with commas used within fields. Fortunately though, this csv only has three columns and the surplus commas are all in the middle column - so if I would manage to delete all comma but the first and the last in each line, I should be fine. How would I get csv reader to do this?
with open('bad.csv') as f, open('good.csv', 'w') as fout: for line in f: first, *middle, last = line.split(',') fout.write(f'{first},"{",".join(middle)}",{last}')
1.4m articles
1.4m replys
5 comments
57.0k users