Python Data Analysis(Second Edition)
上QQ阅读APP看书,第一时间看更新

Preface

Data analysis has a rich history in natural, biomedical, and social sciences. In almost every area of industry, data analysis has gained popularity lately due to the hype around Data Science. Data analysis and Data Science attempt to extract information from data. For that purpose, we use techniques from statistics, machine learning, signal processing, natural language processing, and computer science.

A mind map visualizing Python software that can be used for data analysis can be found in first chapter of this book. The first noticeable thing is that the Python ecosystem is very mature, perse and rich. It includes famous packages such as NumPy, SciPy, and matplotlib. This should not come as a surprise since Python has been around since 1989. Python is easy to learn and use, less verbose than other programming languages, and very readable. Even if you don't know Python, you can pick up the basics within days, especially if you have experience in another programming language. To enjoy this book, you don't need more than the basics. There are plenty of books, courses, and online tutorials that teach Python.

What this book covers

Chapter 1, Getting Started with Python Libraries, gives instructions to install python and fundamental python data analysis libraries. We create a small application using NumPy and draw some basic plots with matplotlib.

Chapter 2, NumPy Arrays, introduces us to NumPy fundamentals and arrays. By the end of this chapter, we will have basic understanding of NumPy arrays and the associated functions.

Chapter 3, The Pandas Primer, introduces us to basic Pandas functionality, data structures and operations.

Chapter 4, Statistics and Linear Algebra, gives a quick overview of linear algebra and statistical functions.

Chapter 5, Retrieving, Processing, and Storing Data, explains how to acquire data in various formats and how to clean raw data and store it.

Chapter 6, Data Visualization, gives an overview of how to plot data with matplotlib and pandas plotting functions.

Chapter 7, Signal Processing and Time Series, contains time series and signal processing examples using sunspot cycles data. The examples use NumPy/SciPy, along with statsmodels.

Chapter 8, Working with Databases, provides information about various databases (relational and NoSQL) and related APIs.

Chapter 9, Analyzing Textual Data and Social Media, analyzes texts for sentiment analysis and topics extraction. A small example is also given of network analysis.

Chapter 10, Predictive Analytics and Machine Learning, explains artificial intelligence with weather prediction as a running example using scikit-learn. Other API are used for algorithms not covered by scikit-learn.

Chapter 11, Environments Outside the Python Ecosystem and Cloud Computing, gives various examples on how to integrate existing code not written in Python. Also, using python in cloud will be demonstrated.

Chapter 12, Performance Tuning, Profiling, and Concurrency, gives hints on improving performance with profiling and Cythoning as key techniques. Relevant frameworks for multicore and distributed systems are also discussed.

Appendix AKey Concepts, gives key terms and their description.

Appendix BUseful Functions, provides a list of key functions of the libraries, that can be used as a ready reference.

Appendix COnline Resources, provides links for the reader to further explore the topics covered in the book.

What you need for this book

The code examples in this book should work on most modern operating systems. For all chapters, Python > 3.5.0 and pip3 is required. You can download Python 3.5.x from https://www.python.org/downloads/. On this webpage, you can find installers for Windows and Mac OS X as well as source archives for Linux, Unix, and Mac OS X. You can find instructions for installing and using python for various operating systems on this webpage: https://docs.python.org/3/using/index.html. Most of the time, we need to run the following command with admin privileges to install various python libraries needed for the content of the book:

$ pip3 install <some library>

The following is a list of python libraries used for the examples:

  • numpy
  • scipy
  • pandas
  • matplotlib
  • ipython
  • jupyter
  • notebook
  • readline
  • scikit-learn
  • rpy2
  • Quandl
  • statsmodels
  • feedparser
  • beautifulsoup4
  • lxml
  • numexpr
  • tables
  • openpyxl
  • xlsxwriter
  • xlrd
  • pony
  • dataset
  • pymongo
  • redis
  • python3-memcache
  • cassandra-driver
  • sqlalchemy
  • nltk
  • networkx
  • theanets
  • nose_parameterized
  • pydot2
  • deap
  • JPype1
  • gprof2dot
  • line_profiler
  • cython
  • cytoolz
  • joblib
  • bottleneck
  • jug
  • mpi4py

Apart from python libraries we also need the following software:

  • Redis server
  • Cassandra
  • Java 8
  • Graphviz
  • Octave
  • R
  • SWIG
  • PCRE
  • Boost
  • gfortran
  • MPI

Usually, the latest version available should work for the above mentioned libraries and software.

Note

Some of the software listed are used for a single example; therefore, please check first whether the example is relevant for you before installing the software.

To uninstall Python packages installed with pip, use the following command:

   $ pip3 uninstall <some library>

Who this book is for

This book is for people with basic knowledge of Python and Mathematics who want to learn how to use Python libraries to analyze data. We try to keep things simple, but it's not possible to cover all the topics in great detail. It may be useful for you to refresh your knowledge of Mathematics using online resources such as Khan Academy and Coursera.

I would recommend the following books by Packt Publishing for further reading:

  • Building Machine Learning Systems with Python, Willi Richert and Luis Pedro Coelho (2013)
  • Learning Cython Programming, Philip Herron (2013)
  • Learning NumPy Array, Ivan Idris (2014)
  • Learning scikit-learn: Machine Learning in Python, Raúl Garreta and Guillermo Moncecchi (2013)
  • Learning SciPy for Numerical and Scientific Computing, Francisco J. Blanco-Silva (2013)
  • Matplotlib for Python Developers, Sandro Tosi (2009)
  • NumPy Beginner's Guide - Second Edition, Ivan Idris (2013)
  • NumPy Cookbook, Ivan Idris (2012)
  • Parallel Programming with Python, Jan Palach (2014)
  • Python Data Visualization Cookbook, Igor Milovanović (2013)
  • Python for Finance, Yuxing Yan (2014)
  • Python Text Processing with NLTK 2.0 Cookbook, Jacob Perkins (2010)

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "It may be necessary to prepend sudo to this command if your current user doesn't have sufficient rights on your system."

A block of code is set as follows:

def pythonsum(n): 
   a = list(range(n)) 
   b = list(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

Any command-line input or output is written as follows:

$ pip3 install numpy scipy pandas matplotlib jupyter notebook
Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply e-mail feedback@packtpub.com, and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book 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.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.
  2. Hover the mouse pointer on the SUPPORT tab at the top.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box.
  5. Select the book for which you're looking to download the code files.
  6. Choose from the drop-down menu where you purchased this book from.
  7. Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows
  • Zipeg / iZip / UnRarX for Mac
  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Python-Data-Analysis-Second-Edition. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/PythonDataAnalysisSecondEdition_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at copyright@packtpub.com with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at questions@packtpub.com, and we will do our best to address the problem.