0

I am trying to import a csv-File and make a dictionary out of it. The problem is that every line is in a string.

For example like this:

""First Name", "Last Name", "Date of Birth""
""Alex", "Turner", "08.09.1978""
""Max", "Parker", "16.02.2003""
""Mike", "Johnsen", "04.12.1999""

I tried to transform it into utf-8 because maybe thought that would be the problem but didn`t work.

import csv

csv_filename = 'Pläne.csv'

with open(csv_filename, encoding='utf-8') as f:
    plaene_dict = csv.DictReader(f)

I have to delete all the double quotes at the beginning and end of every line to get a dictionary out.

Had someone this problem before? How can I transform the csv to be fine for the input. Also have no idea to work around and to delete all the " with python before transform it into in dict. Anyone an idea?

Thanks a lot.

maxmyh

EDIT: Here is a Link to get a sample of the file https://www.transfernow.net/dl/20221109C4Av4YIO

maxmyh
  • 3
  • 3
  • 1
    Can you provide the csv or at least some part of it? – mrin9san Nov 08 '22 at 15:28
  • The question is unclear. VS Code doesn't do anything, it's Python and your code that do load the file. It's hard to tell from that image but it looks like there's really only a single string per line, not multiple fields – Panagiotis Kanavos Nov 08 '22 at 15:28
  • OK, that's not a CSV. The program that created this is broken, at least in the way it quotes fields. Each line starts with a double quote, which means whatever comes next is part of a single text field. All other quotes in the line seem to be escaped though, which means that every line really is a single string. – Panagiotis Kanavos Nov 08 '22 at 15:31
  • Welcome to Stack Overflow. Please take the 2-minute [tour]. Moreover, open [Help] and read at least [ask]. Then, [edit] your question to provide a [mcve]. Please [*do not* use images of code/data/errors](https://meta.stackoverflow.com/a/285557/3439404) in your [mcve]. Copy the actual text, paste it into the question, then format it as code. – JosefZ Nov 08 '22 at 18:09

0 Answers0