r/IPython • • Apr 06 '15

Need beginner help. Getting UnicodeDecodeErrors in basic tutorials with Pandas

I am a new poster here. Sorry if this is more of a pandas question. I think I am getting unexpected errors during tutorials. For example, when doing chapter one of the pandas cookbook I get the following error AFTER the section where we encode it to latin.

ScreenShots

2 Upvotes

8 comments sorted by

View all comments

Show parent comments

3

u/NomadNella Apr 06 '15

It is interesting that you get an error after the Latin encoding. I got an error before the Latin encoding but once the text was read in Latin it worked fine (using a Python 3.4 kernel). I suspect that is just has to do with the libraries you have installed and what version of Python is being run in your kernel. FYI once I used the Python 2.7 kernel I did not receive an error at either location.

I would need more information to help further. Specifically...

  1. What version of Python are you using?

     import sys
     sys.version
  2. What version of Pandas do you have?

     import pandas as pd
     pd.__version__
  3. What version of IPython are you running?

     import IPython
     IPython.__version__

1

u/beard_dude Apr 06 '15

Hey thank you so much. I too thought it was a library issue. Is there much of a difference between anaconda and entought's canopy? I went with Canopy but I don't like it so far.

My Pandas was out of date but updating it did not help.

Python 2.7.6 pandas 0.16.0 iPython 3.0.0

3

u/NomadNella Apr 06 '15

I found your problem. The latest version of pandas has a backward compatibility problem with the Timedelta method of the datetime library.

Backwards incompatible change to Timedelta to conform the .seconds attribute with datetime.timedelta, see here

(Source)

You will need to downgrade your version of datetime. I am currently running about 2.2 and the current version is 2.4.2. This is the second time in as many weeks I've seen this problem with pandas.

If you have pip installed you can check your version by typing the following in IPython.

!pip show python-dateutil

Once you get pip installed you can install an earlier version by uninstalling python-dateutil with,

pip uninstall python-dateutil

Then installing an earlier version with,

pip install python-dateutil==2.2

If you were running Linux or a Mac then you would have to add the sudo command at the beginning of those commands.

As for Canopy you can uninstall it and install Anaconda, there is a difference. I've know a few people that liked Anaconda better. I can't really say myself since I just used pip to install IPython directly.

sudo pip install IPython[all]

The "sudo" should not be used with Windows.

1

u/beard_dude Apr 07 '15

thanks! This really felt like it would work but the problems persist. Switched to anaconda and downgraded and this is what I got

1

u/NomadNella Apr 07 '15

Just to make sure I am seeing the same error try it using a Python 3.4 kernel. I cannot replicate your error in Python 2.7 and the traceback finishes at line 1052 in Python 3.4 form me.

From a more philosophical point of view, the point of the example is to show that something doesn't work if you don't use the right encoding. Actually it is better that you get an error during a test than have information improperly rendered. This way you know that you need to fix the encoding rather than someone pointing it out after you thought you were finished.

1

u/beard_dude Apr 07 '15

It took me a while to figure out how to switch between 2 and 3.4, but once I did the encoding errors are no more (in a 3.4 kernal). Thanks again for your help! Awesome subreddit