jakevdp / PythonDataScienceHandbook

Python Data Science Handbook: full text in Jupyter Notebooks
http://jakevdp.github.io/PythonDataScienceHandbook
MIT License
43.32k stars 17.95k forks source link

Series output #322

Open ameliameyer opened 2 years ago

ameliameyer commented 2 years ago

Under Ch 3: Introducing Pandas Objects, the output shown is different than the output I get when I run the same line of code:

As written in the book:

pd.Series({2:'a', 1:'b', 3:'c'}) 1 b 2 a 3 c dtype: object

Whereas when I run the code:

pd.Series({2:'a', 1:'b', 3:'c'}) 2 a 1 b 3 c dtype: object

Is there something weird going on with my system or is there an error in the text?

nivid26 commented 2 years ago

Hi, Probably its because of different version of python or pandas library which now not allow default sorting. Now, if you want above output then you have to use different command.

pcoates33 commented 2 years ago

Following is from panda release note https://pandas.pydata.org/docs/whatsnew/v0.23.0.html#whatsnew-0230-api-breaking-dict-insertion-order

Python version 3.6 and later, dicts are ordered by insertion order, see PEP 468

If you wish to retain the old behavior while using Python >= 3.6, you can use .sort_index():

pd.Series({2:'a', 1:'b', 3:'c'}).sort_index()