Skip to content

Day38 - bad data in csv file #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alt3red opened this issue Apr 28, 2018 · 3 comments
Closed

Day38 - bad data in csv file #8

alt3red opened this issue Apr 28, 2018 · 3 comments

Comments

@alt3red
Copy link

alt3red commented Apr 28, 2018

Hello,

On Day 38 when loading the Thanksgiving data from the file, there is a error that occurs:

UnicodeDecodeError:

'utf-8' codec can't decode byte 0xed in position 3599: invalid continuation byte

The file gets processed until the record with 'RespondentID':'4335955206' then it errors out.

Also when opening the csv file in PyCharm I get "File was loaded in the wrong encoding: 'UTF-8'"

screen shot 2018-04-27 at 7 08 20 am

The error goes away when removing the line with RspondentID: '4335955152'

@bbelderbos
Copy link
Collaborator

bbelderbos commented Apr 30, 2018

Thanks @alt3red, must indeed be some weird character in RespondentID 4335955206:

import csv

filename = 'thanksgiving-2015-poll-data.csv'

row = None
try:
    with open(filename, 'r', encoding='utf-8') as fin:  # ISO-8859-1
        reader = csv.DictReader(fin)

        for row in reader:
            s = ''.join(row.values())
            s.encode('utf-8')
except:
    print(row['RespondentID’])

If I use ISO-8859-1 it works. See also: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360000004284-File-was-loaded-in-the-wrong-encoding-UTF-8-

@mikeckennedy maybe something to add to the README?

@mikeckennedy
Copy link
Member

Thanks for the heads up guys! I fixed the file and cloned the repo. There is a new link the readme.md now.

https://github.com/talkpython/100daysofcode-with-python-course/blob/master/days/37-39-csv-data-analsys/README.md

I also did a PR back to FiveThirtyEight fixing their data. We'll see if they accept it.

@mikeckennedy
Copy link
Member

PR here:

fivethirtyeight/data#181

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants