Selecting a version of Python to use

This is a classic battle among Python developers—Python 2.7.x or Python 3.x—which is better? Until a year back, it was Python 2.7.x that topped the charts; the reason being it was a stable version. More than 70% of projects used Python 2.7, in the year 2016. This number began to fall and by 2017 it was 63%. This shift in trends was due to the announcement that Python 2.7 would not be maintained from January 1, 2018, meaning that there would be no more bug fixes or new releases. Some libraries released after this announcement are only compatible with Python 3.x. Several businesses have started migrating towards Python 3.x. Hence, as of 2018, Python 3.x is the preferred version.

For further information, please see https://wiki.python.org/moin/Python2orPython3.

The main differences between Python 2.x and 3 include better Unicode support in Python 3, print and exec changed to functions, and integer division. For more details, see What's New in Python 3.0 at http://docs.python.org/3/whatsnew/3.0.html.

However, for scientific, numeric, or data analysis work, Python 2.7 is recommended over Python 3 for the following reason: Python 2.7 is the preferred version for most current distributions, and the support for Python 3.x is not as strong for some libraries, although that is increasingly becoming less of an issue.

For reference, have a look at the documentation titled Will Scientists Ever Move to Python 3? at http://bit.ly/1DOgNuX. Hence, this book will use a mix of Python 2.7 and 3.x as and when required. Translating Python code from 2.7 to 3.x or vice versa is not difficult, and the following documentation can be used as a reference Porting Python 2 Code to Python 3 at http://docs.python.org/2/howto/pyporting.html.

However, there is a middle ground and a way to get the best of the both worlds. One can use the virtualenv package in Python that allows you to create separate light virtual environments from within the installed Python environment. This makes it possible to have, for example, the 2.7 version installed on your machine and to access and run the 3.x version code by launching a virtual environment in your computer using virtualenv. This virtual environment is just a separate installation/instance of Python at a separate location. One can install the packages compatible with that version and do all the computations citing that version/installation while running. You can create as many virtual environments as you wish. This package comes pre-installed with the Anaconda distribution. You can visit the following website for more details on using virtualenvhttps://docs.python-guide.org/dev/virtualenvs/.

The latest major release of pandas—pandas 0.23.4—was in August, 2018. The following are some of the interesting feature upgrades that were made:

  • Reading and writing JSON I pandas has been made more elegant as metadata will be preserved with the orient = True option set.
  • For Python 3.6 and above, the dictionary will be assigned an order based on the order in which the entities were inserted. This order will be carried over to DataFrames or a series created from the dict.
  • Merging and sorting could now make use of a combination of index names and column names.
  • Earlier, the DataFrame.apply() function with axis = 1 returned a list-like object. The latest improvements to pandas have modified the output to be of a consistent shape—either a series or a DataFrame.
  • Categories without any observations can now be controlled in the groupby function through the observed = True setting.
  • DataFrame.all() and DataFrame.any() now accept axis=None to reduce across all axes to a scalar.

But before we start using pandas, let's spend some time installing Python on our computers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset