0

I have a csv file like (Excel Review):

enter image description here

Display only as text: enter image description here

How to handle the commas in the column B, if I want to read this data as csv in Python?

def import_csv():
    with open('file.csv', encoding="ISO-8859-1") as csvfile:

            reader = csv.DictReader(csvfile,delimiter=",")

            for row in reader:
                faelle.append(row)

In this case, If I take as delimiter the "," then the column B will be splited in more columns and this will be not fit for the data.

How can I now read the csv with the delimter "," and keep the column B as one in a pythonic way? So without an intervention/manipulation in the CSV.

In theory, it was declared under this post: Dealing with commas in a CSV file

madik_atma
  • 749
  • 8
  • 26

3 Answers3

0

After reading the actual file, the answer is evident: use the delimiter from the file, that is a semicolon (;):

...
reader = csv.DictReader(csvfile,delimiter=";")
...
Serge Ballesta
  • 136,215
  • 10
  • 111
  • 230
0

Looks like your delimiter is ';' not ',' Try passing that to your reader.

Dries De Rydt
  • 768
  • 4
  • 17
0

Try this:

import csv   
file=open("filename.csv", "r")
reader = csv.reader(file)
reader.next() #if you want to skip the first row
for line in reader:
    faelle.append(line)`enter code here`