Python parse csv file - replace commas with colons

前端 未结 6 1255
孤独总比滥情好
孤独总比滥情好 2020-12-11 02:50

I suspect this is a common problem, but I counldn\'t seem to locate the answer. I am trying to remove all commas from a csv file and replace them with colons. I would normal

6条回答
  •  萌比男神i
    2020-12-11 03:12

    Assuming that the CSV is comma delimited, and you want to replace commas in each entry, I believe the issue is replacing the wrong item:

    for rows in reader:
        for parsed_item in rows:
            parsed_item = parsed_item.replace(',', ':') # Change rows to parsed_item
            writer.writerow(parsed_item)
    

提交回复
热议问题