I've got a simple CSV file I get via email and I tried parsing it.
test.csv containing only:
"Time Interval","SubId","Space Id","Space","Imps.","eCPM (€)","Profit"
"2015-11-15","bottomunit","59457","foo.com","9362","1.92","17.97"
The .py is simple enough (PY3.4.2):
import csv
with open('test.csv') as f:
reader = csv.DictReader(f)
for row in reader:
print(row)
and the output is "messed up":
{'Profit': '17.97', 'Imps.': '9362', '"Time Interval"': '2015-11-15', 'Space': 'foo.com', 'eCPM (€)': '1.92', 'Space Id': '59457', 'SubId': 'bottomunit'}
To be more specific, the Time Interval
fieldname is for some reason not parsed correctly but parsed as "Time Interval"
. Unfortunately this editor does not show it, but there are 3 additional ASCII chars in front of `"Time Inverval"'
As ASCII the whole "Time Inverval"
looks like this:
239, 187, 191, 34, 84, 105, 109, 101, 32, 73, 110, 116, 101, 114, 118, 97, 108, 34
I've already checked the CSV with Notepad++, there's nothing I can tell of in front of the first entry and I have no idea why it is not parsed correctly.
I also tried:
- replacing the first entry with "date"
- removing all spaces
- removing all special characters
- adding
delimiter=','
andquotechar='"'
to the DictReader - tried Python 3.5.0
Problem persists, the parsed first entry is preceeded with ASCII 239, 187, 191
and in double quotes.