jvns/pandas-cookbook

Chapter 1: broken dataframe file is really broken

leonprou opened this issue · 2 comments

In the cookbook Chapter 1 we start with command

broken_df = pd.read_csv('../data/bikes.csv')

That suppose to give a bad input. But when I try this command I get an exception:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 15: invalid continuation byte

The fixed version of the command seems to work good.

I use:
python 3.5.1,
pandas 20.3
MacOS

Update:
After giving another look into the readme file, it is stated that the project is set to work with Python 2.7. But it would be nice to make it Python 3 compatible also.

This works fine with python3. just tested 3.6.5, You are supposed to get UnicodeDecodeError first, but the next works fine.

I don't think a UnicodeDecodeError resulted when the notebook was first written, because in block 5 the author continues to work with broken_df as though Python had assigned it a value without erroring out:

# Look at the first 3 rows
broken_df[:3]

The point of block 4 is to demonstrate that the default settings of read_csv might not work, but maybe the notebook should be updated to acknowledge that an error is actually expected from that line as written, not for the dataframe to be read incorrectly as (I assume) happened in Python 2.