Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Python Data Analysis
Python Data Analysis

Python Data Analysis: Learn how to apply powerful data analysis techniques with popular open source Python modules

eBook
₱1571.99 ₱2245.99
Paperback
₱2806.99
Subscription
Free Trial

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

Python Data Analysis

Chapter 1. Getting Started with Python Libraries

Let's get started. We can find a mind map describing software that can be used for data analysis at http://www.xmind.net/m/WvfC/. Obviously, we can't install all of this software in this chapter. We will install NumPy, SciPy, matplotlib, and IPython on different operating systems and have a look at some simple code that uses NumPy.

NumPy is a fundamental Python library that provides numerical arrays and functions.

SciPy is a scientific Python library, which supplements and slightly overlaps NumPy. NumPy and SciPy historically shared their code base but were later separated.

matplotlib is a plotting library based on NumPy. You can read more about matplotlib in Chapter 6, Data Visualization.

IPython provides an architecture for interactive computing. The most notable part of this project is the IPython shell. We will cover the IPython shell later in this chapter.

Installation instructions for the other software we need will be given throughout the book at the appropriate time. At the end of this chapter, you will find pointers on how to find additional information online if you get stuck or are uncertain about the best way to solve problems.

In this chapter, we will cover:

  • Installing Python, SciPy, matplotlib, IPython, and NumPy on Windows, Linux, and Macintosh
  • Writing a simple application using NumPy arrays
  • Getting to know IPython
  • Online resources and help

Software used in this book

The software used in this book is based on Python, so you are required to have Python installed. On some operating systems, Python is already installed. You, however, need to check whether the Python version is compatible with the software version you want to install. There are many implementations of Python, including commercial implementations and distributions. In this book, we will focus on the standard CPython implementation, which is guaranteed to be compatible with NumPy.

Note

You can download Python from https://www.python.org/download/. On this website, we can find installers for Windows and Mac OS X as well as source archives for Linux, Unix, and Mac OS X.

The software we will install in this chapter has binary installers for Windows, various Linux distributions, and Mac OS X. There are also source distributions if you prefer that. You need to have Python 2.4.x or above installed on your system. Python 2.7.x is currently the best Python version to have because most Scientific Python libraries support it. Python 2.7 will be supported and maintained until 2020. After that, we will have to switch to Python 3.

Installing software and setup

We will learn how to install and set up NumPy, SciPy, matplotlib, and IPython on Windows, Linux and Mac OS X. Let's look at the process in detail.

On Windows

Installing on Windows is, fortunately, a straightforward task that we will cover in detail. You only need to download an installer and a wizard will guide you through the installation steps. We will give you steps to install NumPy here. The steps to install the other libraries are similar. The actions we will take are as follows:

  1. Download installers for Windows from the SourceForge website (refer to the following table). The latest release versions may change, so just choose the one that fits your setup best.
  2. Choose the appropriate version. In this example, we chose numpy-1.8.1-win32-superpack-python2.7.exe.
  3. Open the EXE installer by double-clicking on it.
  4. Now, we can see a description of NumPy and its features. Click on the Next button.

    If you have Python installed, it should automatically be detected. If it is not detected, maybe your path settings are wrong.

    Tip

    At the end of this chapter, resources are listed just in case you have problems installing NumPy.

  5. Click on the Next button if Python is found; otherwise, click on the Cancel button and install Python (NumPy cannot be installed without Python). Click on the Next button. This is the point of no return. Well, kind of, but it is best to make sure that you are installing to the proper directory, and so on and so forth. Now the real installation starts. This may take a while.

    Note

    The situation around installers is rapidly evolving. Other alternatives exist in various stages of maturity (see http://www.scipy.org/install.html). It might be necessary to put the msvcp71.dll file in your system32 directory located at C:\Windows\. You can get it from http://www.dll-files.com/dllindex/dll-files.shtml?msvcp71.

On Linux

Installing the recommended software on Linux depends on the distribution you have. We will discuss how you would install NumPy from the command line;you could probably use graphical installers depending on your distribution (distro). The commands to install matplotlib, SciPy, and IPython are the same; only the package names are different. Installing matplotlib, SciPy, and IPython is recommended but optional.

Most Linux distributions have NumPy packages. We will go through the necessary commands for some of the popular Linux distributions as follows:

  • Run the following instructions from the command line to install NumPy on Red Hat:
    $ yum install python-numpy
    
  • To install NumPy on Mandriva, run the following command-line instruction:
    $ urpmi python-numpy
    
  • To install NumPy on Gentoo, run the following command-line instruction:
    $ sudo emerge numpy
    
  • To install NumPy on Debian or Ubuntu, we need to type the following:
    $ sudo apt-get install python-numpy
    

The following table gives an overview of the Linux distributions and corresponding package names for NumPy, SciPy, matplotlib, and IPython:

Linux distribution

NumPy

SciPy

matplotlib

IPython

Arch Linux

python-numpy

python-scipy

python-matplotlib

Ipython

Debian

python-numpy

python-scipy

python-matplotlib

Ipython

Fedora

numpy

python-scipy

python-matplotlib

Ipython

Gentoo

dev-python/numpy

scipy

matplotlib

ipython

openSUSE

python-numpy, python-numpy-devel

python-scipy

python-matplotlib

ipython

Slackware

numpy

scipy

matplotlib

ipython

On Mac OS X

You can install NumPy, matplotlib, and SciPy on Mac OS X with a graphical installer or from the command line with a port manager, such as MacPorts or Fink, depending on your preference. The prerequisite is to install XCode, as it is not part of OS X releases. We will install NumPy with a GUI installer using the following steps:

  1. We can get a NumPy installer from the SourceForge website at http://sourceforge.net/projects/numpy/files/. Similar files exist for matplotlib and SciPy.
  2. Just change numpy in the previous URL to scipy or matplotlib to get installers of the respective libraries. IPython didn't have a GUI installer at the time of writing this.
  3. Download the appropriate DMG file; usually the latest one is the best.

    Another alternative is SciPy Superpack (https://github.com/fonnesbeck/ScipySuperpack).

Whichever option you choose, it is important to make sure that updates that impact the system Python library don't negatively influence already-installed software by not building against the Python library provided by Apple. Install NumPy, matplotlib, and SciPy using the following steps:

  1. Open the DMG file (in this example, numpy-1.8.1-py2.7-python.org-macosx10.6.dmg).
  2. Double-click on the icon of the opened box—the one with a subscript that ends with .mpkg. We will be presented with the welcome screen of the installer.
  3. Click on the Continue button to go to the Read Me screen, where we will be presented with a short description of NumPy.
  4. Click on the Continue button to go to the License screen.
  5. Read the license, click on the Continue button, and then click on the Accept button when prompted to accept the license. Continue through the screens that follow from there, and click on the Finish button at the end.

Alternatively, we can install the libraries through the MacPorts route, with Fink or Homebrew. The following installation commands install all these packages. We only need NumPy for all the tutorials in this book, so please omit the packages you are not interested in.

  • To install with MacPorts, type in the following command:
    $ sudo port install py-numpy py-scipy py-matplotlib py-ipython
    
  • Fink also has packages for NumPy, such as scipy-core-py24, scipy-core-py25, and scipy-core-py26. The SciPy packages are scipy-py24, scipy-py25, and scipy-py26. We can install NumPy and other recommended packages that we will be using in this book for Python 2.6 with the following command:
    $ fink install scipy-core-py26 scipy-py26 matplotlib-py26
    

Building NumPy, SciPy, matplotlib, and IPython from source

As a last resort or if we want to have the latest code, we can build from source. In practice, it shouldn't be that hard, although depending on your operating system, you might run into problems. As operating systems and related software are rapidly evolving, in such cases, the best you can do is search online or ask for help. In this chapter, we give pointers on good places to look for help.

The source code can be retrieved with git or as an archive from GitHub. The steps to install NumPy from source are straightforward and given here. We can retrieve the source code for NumPy with git as follows:

$ git clone git://github.com/numpy/numpy.git numpy

Note

There are similar commands for SciPy, matplotlib, and IPython (refer to the table that follows after this piece of information). The IPython source code can be downloaded from https://github.com/ipython/ipython/releases as a source archive or ZIP file. You can then unpack it with your favorite tool or with the following command:

$ tar -xzf ipython.tar.gz

Please refer to the following table for the git commands and source archive/zip links:

Library

Git command

Tarball/zip URL

NumPy

git clone git://github.com/numpy/numpy.git numpy

https://github.com/numpy/numpy/releases

SciPy

git clone http://github.com/scipy/scipy.git scipy

https://github.com/scipy/scipy/releases

matplotlib

git clone git://github.com/matplotlib/matplotlib.git

https://github.com/matplotlib/matplotlib/releases

IPython

git clone --recursive https://github.com/ipython/ipython.git

https://github.com/ipython/ipython/releases

Install on /usr/local with the following command from the source code directory:

$ python setup.py build
$ sudo python setup.py install --prefix=/usr/local

To build, we need a C compiler such as GCC and the Python header files in the python-dev or python-devel package.

Installing with setuptools

If you have setuptools or pip, you can install NumPy, SciPy, matplotlib, and IPython with the following commands. For each library, we give two commands, one for setuptools and one for pip. You only need to choose one command per pair:

$ easy_install numpy
$ pip install numpy

$ easy_install scipy
$ pip install scipy

$ easy_install matplotlib
$ pip install matplotlib

$ easy_install ipython
$ pip install ipython

It may be necessary to prepend sudo to these commands if your current user doesn't have sufficient rights on your system.

NumPy arrays

After going through the installation of NumPy, it's time to have a look at NumPy arrays. NumPy arrays are more efficient than Python lists when it comes to numerical operations. NumPy arrays are, in fact, specialized objects with extensive optimizations. NumPy code requires less explicit loops than equivalent Python code. This is based on vectorization.

If we go back to highschool mathematics, then we should remember the concepts of scalars and vectors. The number 2, for instance, is a scalar. When we add 2 to 2, we are performing scalar addition. We can form a vector out of a group of scalars. In Python programming terms, we will then have a one-dimensional array. This concept can, of course, be extended to higher dimensions. Performing an operation on two arrays, such as addition, can be reduced to a group of scalar operations. In straight Python, we will do that with loops going through each element in the first array and adding it to the corresponding element in the second array. However, this is more verbose than the way it is done in mathematics. In mathematics, we treat the addition of two vectors as a single operation. That's the way NumPy arrays do it too, and there are certain optimizations using low-level C routines, which make these basic operations more efficient. We will cover NumPy arrays in more detail in the following chapter, Chapter 2, NumPy Arrays.

A simple application

Imagine that we want to add two vectors called a and b. The word vector is used here in the mathematical sense, which means a one-dimensional array. We will learn in Chapter 3, Statistics and Linear Algebra, about specialized NumPy arrays that represent matrices. The vector a holds the squares of integers 0 to n; for instance, if n is equal to 3, a contains 0, 1, or 4. The vector b holds the cubes of integers 0 to n, so if n is equal to 3, then the vector b is equal to 0, 1, or 8. How would you do that using plain Python? After we come up with a solution, we will compare it with the NumPy equivalent.

The following function solves the vector addition problem using pure Python without NumPy:

def pythonsum(n):
   a = range(n)
   b = range(n)
   c = []

   for i in range(len(a)):
       a[i] = i ** 2
       b[i] = i ** 3
       c.append(a[i] + b[i])

   return c

The following is a function that solves the vector addition problem with NumPy:

def numpysum(n):
  a = numpy.arange(n) ** 2
  b = numpy.arange(n) ** 3
  c = a + b
  return c

Notice that numpysum() does not need a for loop. Also, we used the arange() function from NumPy, which creates a NumPy array for us with integers from 0 to n. The arange() function was imported; that is why it is prefixed with numpy.

Now comes the fun part. Remember that it was mentioned in the Preface that NumPy is faster when it comes to array operations. How much faster is Numpy, though? The following program will show us by measuring the elapsed time in microseconds for the numpysum() and pythonsum() functions. It also prints the last two elements of the vector sum. Let's check that we get the same answers using Python and NumPy:

#!/usr/bin/env/python

import sys
from datetime import datetime
import numpy as np

"""
 This program demonstrates vector addition the Python way.
 Run from the command line as follows

  python vectorsum.py n

 where n is an integer that specifies the size of the vectors.

 The first vector to be added contains the squares of 0 up to n.
 The second vector contains the cubes of 0 up to n.
 The program prints the last 2 elements of the sum and the elapsed time.
"""

def numpysum(n):
   a = np.arange(n) ** 2
   b = np.arange(n) ** 3
   c = a + b

   return c

def pythonsum(n):
   a = range(n)
   b = range(n)
   c = []

   for i in range(len(a)):
       a[i] = i ** 2
       b[i] = i ** 3
       c.append(a[i] + b[i])

   return c

size = int(sys.argv[1])

start = datetime.now()
c = pythonsum(size)
delta = datetime.now() - start
print "The last 2 elements of the sum", c[-2:]
print "PythonSum elapsed time in microseconds", delta.microseconds

start = datetime.now()
c = numpysum(size)
delta = datetime.now() - start
print "The last 2 elements of the sum", c[-2:]
print "NumPySum elapsed time in microseconds", delta.microseconds

The output of the program for 1000, 2000, and 3000 vector elements is as follows:

$ python vectorsum.py 1000
The last 2 elements of the sum [995007996, 998001000]
PythonSum elapsed time in microseconds 707
The last 2 elements of the sum [995007996 998001000]
NumPySum elapsed time in microseconds 171

$ python vectorsum.py 2000
The last 2 elements of the sum [7980015996, 7992002000]
PythonSum elapsed time in microseconds 1420
The last 2 elements of the sum [7980015996 7992002000]
NumPySum elapsed time in microseconds 168

$ python vectorsum.py 4000
The last 2 elements of the sum [63920031996, 63968004000]
PythonSum elapsed time in microseconds 2829
The last 2 elements of the sum [63920031996 63968004000]
NumPySum elapsed time in microseconds 274

Clearly, NumPy is much faster than the equivalent normal Python code. One thing is certain; we get the same results whether we are using NumPy or not. However, the result that is printed differs in representation. Notice that the result from the numpysum() function does not have any commas. How come? Obviously, we are not dealing with a Python list but with a NumPy array. We will learn more about NumPy arrays in the next chapter, Chapter 2, NumPy Arrays.

Using IPython as a shell

Scientists, data analysts, and engineers are used to experimenting. IPython was created by scientists with experimentation in mind. The interactive environment that IPython provides is viewed by many as a direct answer to MATLAB, Mathematica, and Maple.

The following is a list of features of the IPython shell:

  • Tab completion, which helps you find a command
  • History mechanism
  • Inline editing
  • Ability to call external Python scripts with %run
  • Access to system commands
  • The pylab switch
  • Access to the Python debugger and profiler

The following list describes how to use the IPython shell:

  • The pylab switch: The pylab switch automatically imports all the Scipy, NumPy, and matplotlib packages. Without this switch, we would have to import these packages ourselves.

    All we need to do is enter the following instruction on the command line:

    $ ipython -pylab
    Type "copyright", "credits" or "license" for more information.
    
    IPython 2.0.0-dev -- An enhanced Interactive Python.
    ?         -> Introduction and overview of IPython's features.
    %quickref -> Quick reference.
    help      -> Python's own help system.
    object?   -> Details about 'object', use 'object??' for extra details.
    
    Welcome to pylab, a matplotlib-based Python environment [backend: MacOSX].
    For more information, type 'help(pylab)'.
    
    In [1]: quit()
    

    Tip

    The quit() function or Ctrl + D quits the IPython shell.

  • Saving a session: We might want to be able to go back to our experiments. In IPython, it is easy to save a session for later use, with the following command:
    In [1]: %logstart
    Activating auto-logging. Current session state plus future input saved.
    Filename       : ipython_log.py
    Mode           : rotate
    Output logging : False
    Raw input log  : False
    Timestamping   : False
    State          : active
    

    Logging can be switched off as follows:

    In [9]: %logoff
    Switching logging OFF
    
  • Executing system shell command: Execute a system shell command in the default IPython profile by prefixing the command with the ! symbol. For instance, the following input will get the current date:
    In [1]: !date
    

    In fact, any line prefixed with ! is sent to the system shell. Also, we can store the command output as shown here:

    In [2]: thedate = !date
    In [3]: thedate
    
  • Displaying history: We can show the history of commands with the %hist command, for example:
    In [1]: a = 2 + 2
    
    In [2]: a
    Out[2]: 4
    
    In [3]: %hist
    a = 2 + 2
    a
    %hist
    

    This is a common feature in Command Line Interface (CLI) environments. We can also search through the history with the -g switch as follows:

    In [5]: %hist -g a = 2
        1: a = 2 + 2
    

    Tip

    Downloading the example code

    You can download the example code files for all the Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

We saw a number of so-called magic functions in action. These functions start with the % character. If the magic function is used on a line by itself, the % prefix is optional.

Reading manual pages

When we are in IPython's pylab mode ($ ipython –pylab), we can open manual pages for NumPy functions with the help command. It is not necessary to know the name of a function. We can type a few characters and then let tab completion do its work. Let's, for instance, browse the available information for the arange() function.

We can browse the available information in either of the following two ways:

  • Calling the help function: Call the help command. Type in a few characters of the function and press the Tab key.
    Reading manual pages
  • Querying with a question mark: Another option is to append a question mark to the function name. You will then, of course, need to know the function name, but you don't have to type help, for example:
    In [3]: arange?
    

    Tab completion is dependent on readline, so you need to make sure that it is installed. It can be installed with setuptools with one of the following commands:

    $ easy_install readline
    $ pip install readline
    

    The question mark gives you information from docstrings.

IPython notebooks

If you have browsed the Internet looking for information on Python, it is very likely that you have seen IPython notebooks. These are web pages with text, charts, and Python code in a special format. Have a look at these notebook collections at the following links:

Often, the notebooks are used as an educational tool or to demonstrate Python software. We can import or export notebooks either from plain Python code or using the special notebook format. The notebooks can be run locally, or we can make them available online by running a dedicated notebook server. Certain cloud computing solutions, such as Wakari and PiCloud, allow you to run notebooks in the Cloud. Cloud computing is one of the topics of Chapter 11, Environments Outside the Python Ecosystem and Cloud Computing.

Where to find help and references

The main documentation website for NumPy and SciPy is at http://docs.scipy.org/doc/. Through this web page, we can browse the NumPy reference guide at http://docs.scipy.org/doc/numpy/reference/ and the user guide as well as several tutorials.

The popular Stack Overflow software development forum has hundreds of questions tagged numpy. To view them, go to http://stackoverflow.com/questions/tagged/numpy.

This might be stating the obvious, but numpy can also be substituted with scipy, ipython, or almost anything of interest. If you are really stuck with a problem or you want to be kept informed of NumPy development, you can subscribe to the NumPy discussion mailing list. The e-mail address is . The number of e-mails per day is not too high, and there is almost no spam to speak of. Most importantly, developers actively involved with NumPy also answer questions asked on the discussion group. The complete list can be found at http://www.scipy.org/Mailing_Lists.

For IRC users, there is an IRC channel on irc://irc.freenode.net. The channel is called #scipy, but you can also ask NumPy questions since SciPy users also have knowledge of NumPy, as SciPy is based on NumPy. There are at least 50 members on the SciPy channel at all times.

Summary

In this chapter, we installed NumPy, SciPy, matplotlib, and IPython that we will be using in tutorials. We got a vector addition program working and convinced ourselves that NumPy offers superior performance. In addition, we explored the available documentation and online resources.

In the next chapter, Chapter 2, NumPy Arrays, we will take a look under the hood of NumPy and explore some fundamental concepts including arrays and data types.

Left arrow icon Right arrow icon

Description

This book is for programmers, scientists, and engineers who have knowledge of the Python language and know the basics of data science. It is for those who wish to learn different data analysis methods using Python and its libraries. This book contains all the basic ingredients you need to become an expert data analyst.

What you will learn

  • Install open source Python modules on various platforms
  • Get to know about the fundamentals of NumPy including arrays
  • Manipulate data with pandas
  • Retrieve, process, store, and visualize data
  • Understand signal processing and timeseries data analysis
  • Work with relational and NoSQL databases
  • Discover more about data modeling and machine learning
  • Get to grips with interoperability and cloud computing

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 28, 2014
Length: 348 pages
Edition : 1st
Language : English
ISBN-13 : 9781783553365
Category :
Languages :
Concepts :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

Publication date : Oct 28, 2014
Length: 348 pages
Edition : 1st
Language : English
ISBN-13 : 9781783553365
Category :
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₱260 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just ₱260 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 7,859.97
Python Data Science Essentials
₱2245.99
R for Data Science
₱2806.99
Python Data Analysis
₱2806.99
Total 7,859.97 Stars icon

Table of Contents

16 Chapters
1. Getting Started with Python Libraries Chevron down icon Chevron up icon
2. NumPy Arrays Chevron down icon Chevron up icon
3. Statistics and Linear Algebra Chevron down icon Chevron up icon
4. pandas Primer Chevron down icon Chevron up icon
5. Retrieving, Processing, and Storing Data Chevron down icon Chevron up icon
6. Data Visualization Chevron down icon Chevron up icon
7. Signal Processing and Time Series Chevron down icon Chevron up icon
8. Working with Databases Chevron down icon Chevron up icon
9. Analyzing Textual Data and Social Media Chevron down icon Chevron up icon
10. Predictive Analytics and Machine Learning Chevron down icon Chevron up icon
11. Environments Outside the Python Ecosystem and Cloud Computing Chevron down icon Chevron up icon
12. Performance Tuning, Profiling, and Concurrency Chevron down icon Chevron up icon
A. Key Concepts Chevron down icon Chevron up icon
B. Useful Functions Chevron down icon Chevron up icon
C. Online Resources Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.9
(16 Ratings)
5 star 37.5%
4 star 31.3%
3 star 18.8%
2 star 6.3%
1 star 6.3%
Filter icon Filter
Top Reviews

Filter reviews by




Miss Fatty Nov 23, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
A really a good source for analysts/scientists using the python language. The author does a great job introducing the reader to core Python libraries, I found the information to be digestible even with my limited knowledge of the subject matter. I must say very well written: covers concrete practical examples to show you the capabilities of a suite of tools. I am very happy with the purchase. This book is helping me move my skill set beyond R and into Python.
Amazon Verified review Amazon
Mikel Viera Nov 25, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
If you're looking for a book that discusses Python data analysis in a broadpractical sense, this is the book. The author conveys his data analysisexperience into the text really well. The chapters are genuinely helpfulwith well written tutorials on Pythons excellent libraries: NumPy, SciPy,Pandas, IPython, Matplotlib etc.One of the better books I've read on the subject . Highly recommended!
Amazon Verified review Amazon
Harris Nov 23, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Really happy with it so far. This is very nicely written and a must have for data analysts using Python. Author covers examples with all the main libraries including NumPY, SciPY, Ipython in a clear concise manner. Well structured and focused throughout. Nice to see Sci-kit coverage too! (Looking forward to the Machine learning chapters).
Amazon Verified review Amazon
Daniel Lee Feb 22, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
As an experienced Python developer, I really enjoyed the book. That being said, it has a targeted audience and if you aren't in it, you'll probably be happier not picking it up. The book is aimed at people who:1. Already know Python2. Already know data analysis3. Want a broad overview rather than in-depth explanationsThe book got interesting for me in chapter 2, where NumPy arrays were explained, as well as a lot of the operations that can be done on them. I have limited experience with NumPy, and I found the section just in-depth enough to be interesting and just shallow enough to allow me to use it as a springboard to find what I needed to in other areas. As NumPy is a dependency for just about anything that does any number crunching in Python, it was good to have these basics.What really opened my eye, though, was chapter 4 - the pandas primer. I'm a heavy R user for research and have often wished that I could do more data analysis in Python. pandas allows you to do this as comfortably, if not more comfortably, than in Python, and because the package is in Python it's a lot faster and a lot easier to embed in other software. I'm in the middle of a project at the moment and had been struggling with R - the implementation of an analysis milestone was just too slow. After reading this chapter, I implemented it in Python and was able to notice amaing speed improvements, not to mention the maintainability advantages. Data analysis is fun again!The rest of the book is more of a quick blowthrough of what's possible in Python. Although the author doesn't discuss any topic in depth, he does refer you to other books and websites. The purpose was to show readers what's possible. In my opinion, this is basically a longer preview of several data analysis possibilities. If you know roughly what you want to do in the following areas:* Processing common formats like CSV, HDF or XML* Interfacing with databases* Interfacing with other languages* Visualizing data* Signal processing and machine learning* Text analysis* Profiling, performance optimization and parallelizationthen you'll find some good recommendations here with short descriptions and examples that will help you decide which of the packages introduced here are interesting. If you want more, you'll have to dig on your own, but the author gives you good starting points and with such a variety of topics I don't know how one could realistically expect anything else.All in all, a great read, especially for data analysts whose main question is "Can I do this in Python, and if yes, how?"
Amazon Verified review Amazon
Michael Bright Feb 17, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book provides a very broad overview of toolkits and methods available forperforming Data Analysis with Python - and it does an excellent job at that.Whilst breadth of coverage will always be a trade off against depth, the bookprovides good balance by providing runnable code and data examplesacross the broad spectrum of tools and techniques referred to.It also provides many internet references to allow to dig deeper into particular subjects.Even in chapters where reference is made to interfacing to non-Pythonenvironments (Matlab/Octave, R, Java, SWIG, Boost, Fortran), external cloudenvironments (GAE, PythonAnywhere, Wakari) or Performance tools (Profiling,Cython, JobLib, JUG, MPI) or many Databases/tools code examples are given.Each chapter finishes with a summary as well as a preface of the followingchapter - there are many useful forward and backward references in the bookmaking it easy to digest and find information.The book starts with setting up the environment (either building from sourceor installing on various operating systems), followed by a brief introduction to Numpybefore demonstrating how much faster Numpy is than Python native arrays whilstbenefiting from array abstractions.Chapters 2,3,4 cover Numpy in detail (data types, slicing and shaping arrays,boolean indexing to select subsets of data), some Statistics and LinearAlgebra (probability distributions, SciPy, removing extreme values, plottingimages and graphs), Pandas (DataFrames and Series, concatenating frames, basicanalysis and aggregation of data).Chapter 5 covers retrieving of data from a wide variety of sources/formats(CSV, .npy Pickled files, HDF5, REST/json, RSS, HTML/BeautifulSoup, Excel)complete with working examples.Chapter 6 delves into Data Visualization using matplotlib, or Pandas.plots,for a variety of types of plots (histogram, scatter, bubble, lag, log, autocorrelation plots).Chapter 7 covers Signal Processing and Time series. It shows the statsmodelsubpackage and dicusses moving averages, windows, (boxcar, triangle, hamming),co-integration/autocorrelation, auto-regression, Fourier transforms.Chapter 8 provides information on interfacing with Databases and brieflycovers many ways to do this using Sqlite, SQLAlchemy, Pony, Dataset, MongoDB,Redis or Cassandra, again with usable examples.Chapters 9 and 10 go deeper into analysis covering analysis of textual data,social media data through natural language processing (NLTK), Bayesclassification, sentiment analysis, followed by predictive analysis usingscikit-learn, support vector machines, ElasticNetCV, neural nets, decisiontrees and clustering.Chapter 11 covers interfacing to external environments through the integrationwith other toolkits such as Matlab/Octave, languages such as R, Fortran, Java,C and use of some Python supporting cloud platforms (Googles' GAE,PythonAnywhere, Wakari).The final chapter 12 addresses performance profiling and concurrency -covering tools such as ****PROFILER****, Cython, several process pool andparallel processing tools and JUG for MapReduce.Overall this book, and indeed each chapter, provide an excellent coverageof its' stated subject with many examples and links to external information.It is well worth buying for someone relatively new to Data Analysis in Pythonwho wants an introduction to the broad panoply of tools and techniquescurrently available.A few minor points follow which I feel could improve the book.Just a few of the examples given were not particularly interesting (e.g.grouping of foods/pricing/weather) but given the diversity of examples in thebook this is understandable.Although there are many diverse examples - using diverse toolkits, but alsodata scenarios I felt that these exercises often lacked the final step ofproviding some analysis. Examples would finish with a set of figures, or aplot which may be considered to be self evident but I felt lacked a conclusionof the form "notice how there is a cluster of values around ...","in this graph we see that there is a correlation ...", or"and so this result demonstrates the validity of our assumption that ...".The first Appendix is called "Key Concepts" - I'd have called this a Glossaryincluding an entry for all the tools touched on in the book and I've had madereference to this glossary early on in the book.I'd also have liked to see a section comparing the main tools so that it isclear in which situation to use different tools.That said the appendix is useful and it is followed by other useful appendices"Useful Functions" summarizing the most useful functions of Numpy, Pandas etc,and "Online Resources" which provides an extensive list of resources (tools,datasources, informative sites) referred to throughout the book and finally avery complete index.At various chapters there we see module 'subpackage lists' whilst it'sinteresting to be able to produce such lists, they're not actually veryreadable in the book.Once again, a very excellent introduction.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.