




























































































Estude fácil! Tem muito documento disponível na Docsity
Ganhe pontos ajudando outros esrudantes ou compre um plano Premium
Esta página não é visível na pré-visualização
Não perca as partes importantes!





























































































iii
Contents at a Glance
About the Author ���������������������������������������������������������������������������������������������������xvii
About the Technical Reviewer ��������������������������������������������������������������������������������xix
Acknowledgments ��������������������������������������������������������������������������������������������������xxi
■Chapter 1: An Introduction to Data Analysis ��������������������������������������������������������� 1
■Chapter 2: Introduction to the Python’s World ���������������������������������������������������� 13
■Chapter 3: The NumPy Library����������������������������������������������������������������������������� 35
■Chapter 4: The pandas Library—An Introduction ������������������������������������������������ 63
■Chapter 5: pandas: Reading and Writing Data��������������������������������������������������� 103
■Chapter 6: pandas in Depth: Data Manipulation ������������������������������������������������ 131
■Chapter 7: Data Visualization with matplotlib ��������������������������������������������������� 167
■Chapter 8: Machine Learning with scikit-learn ������������������������������������������������� 237
■Chapter 9: An Example—Meteorological Data �������������������������������������������������� 265
■Chapter 10: Embedding the JavaScript D3 Library in IPython Notebook ��������� 289
■Chapter 11: Recognizing Handwritten Digits����������������������������������������������������� 311
■Appendix A: Writing Mathematical Expressions with LaTeX ����������������������������� 317
■Appendix B: Open Data Sources ������������������������������������������������������������������������ 327
Index ��������������������������������������������������������������������������������������������������������������������� 331
Contents
About the Author ���������������������������������������������������������������������������������������������������xvii
About the Technical Reviewer ��������������������������������������������������������������������������������xix
vii
viii
x
xi
xiii
xiv
xvii
About the Author
Fabio Nelli is an IT Scientific Application Specialist at IRBM Science Park, a private research center in Pomezia, Roma (Italy). He has been a computer consultant for many years at IBM, EDS, Merck Sharp, and Dohme, along with several banks and insurance companies. He has an Organic Chemistry degree and many years of experience in Information Technologies and Automation Systems applied to Life Sciences (Tech Specialist at Beckman Coulter Italy and Spain). He is currently developing Java applications that interface Oracle databases with scientific instrumentations, generating data and Web server applications and providing analysis of the results to researchers in real time. Moreover, he is the coordinator of the Meccanismo Complesso community (www.meccanismocomplesso.org).
xix
About the Technical Reviewer
Shubham Singh Tomar is a Data Engineer at Predikt.co. He lives and works in Bangalore, India. On weekends he volunteers to work on Data Science projects for NGOs and social organizations with the Bangalore chapter of. He writes about Python, Data Science and Machine Learning on his blog: shubhamtomar.me.
1
An Introduction to Data Analysis
With this chapter, you will begin to take the first steps in the world of data analysis, seeing in detail all the concepts and processes that make up this discipline. The concepts discussed in this chapter will be helpful background for the following chapters, where these concepts and procedures will be applied in the form of Python code, through the use of several libraries that will be discussed in just as many chapters.
Data Analysis In a world increasingly centralized around information technology, huge amounts of data are produced and stored each day. Often these data come from automatic detection systems, sensors, and scientific instrumentation, or you produce them daily and unconsciously every time you make a withdrawal from the bank or make a purchase, when you record on various blogs, or even when you post on social networks. But what are the data? The data actually are not information, at least in terms of their form. In the formless stream of bytes, at first glance it is difficult to understand their essence if not strictly the number, word, or time that they report. Information is actually the result of processing, which taking into account a certain set of data, extracts some conclusions that can be used in various ways. This process of extracting information from the raw data is precisely data analysis. The purpose of data analysis is precisely to extract information that is not easily deducible but that, when understood, leads to the possibility of carrying out studies on the mechanisms of the systems that have produced them, thus allowing the possibility of making forecasts of possible responses of these systems and their evolution in time. Starting from a simple methodical approach on data protection, data analysis has become a real discipline leading to the development of real methodologies generating models. The model is in fact the translation into a mathematical form of a system placed under study. Once there is a mathematical or logical form able to describe system responses under different levels of precision, you can then make predictions about its development or response to certain inputs. Thus the aim of data analysis is not the model, but the goodness of its predictive power. The predictive power of a model depends not only on the quality of the modeling techniques but also on the ability to choose a good dataset upon which to build the entire data analysis. So the search for data , their extraction , and their subsequent preparation , while representing preliminary activities of an analysis, also belong to the data analysis itself, because of their importance in the success of the results. So far we have spoken of data, their handling, and their processing through calculation procedures. In parallel to all stages of processing of the data analysis, various methods of data visualization have been developed. In fact, to understand the data, both individually and in terms of the role they play in the entire data set, there is no better system than to develop the techniques of graphic representation capable of transforming information, sometimes implicitly hidden, in figures, which help you more easily understand their meaning. Over the years lots of display modes have been developed for different modes of data display: the charts.
Chapter 1 ■ an IntroduCtIon to data analysIs
2
At the end of the data analysis, you will have a model and a set of graphical displays and then you will be able to predict the responses of the system under study; after that, you will move to the test phase. The model will be tested using another set of data for which we know the system response. These data are, however, not used for the definition of the predictive model. Depending on the ability of the model to replicate real observed responses, you will have an error calculation and a knowledge of the validity of the model and its operating limits. These results can be compared with any other models to understand if the newly created one is more efficient than the existing ones. Once you have assessed that, you can move to the last phase of data analysis—the deployment. This consists of the implementation of the results produced by the data analysis, namely, the implementation of the decisions to be taken based on the predictions generated by the model and the risks that such a decision will also be predicted. Data analysis is a discipline that is well suited to many professional activities. So, knowledge of what it is and how it can be put into practice will be relevant for consolidating the decisions to be made. It will allow us to test hypotheses, and to understand more deeply the systems analyzed.
Knowledge Domains of the Data Analyst Data analysis is basically a discipline suitable to the study of problems that may occur in several fields of applications. Moreover, in processes of data analysis you have many tools and methodologies that require good knowledge of computing and mathematical and statistical concepts. So a good data analyst must be able to move and act in many different disciplinary areas. Many of these disciplines are the basis of the methods of data analysis, and proficiency in them is almost necessary. Knowledge of other disciplines is necessary depending on the area of application and study of the particular data analysis project you are about to undertake, and, more generally, sufficient experience in these areas can just help you better understand the issues and the type of data needed to start with the analysis. Often, regarding major problems of data analysis, it is necessary to have an interdisciplinary team of experts made up of members who are all able to contribute in the best possible way in their respective fields of competence. Regarding smaller problems, a good analyst must be able to recognize problems that arise during data analysis, inquire to find out which disciplines and skills are necessary to solve the problem, study these disciplines, and maybe even ask the most knowledgeable people in the sector. In short, the analyst must be able to know how to search not only for data, but also for information on how to treat them.
Knowledge of Computer Science is a basic requirement for any data analyst. In fact, only one who has good knowledge of and experience in Computer Science is able to efficiently manage the necessary tools for data analysis. In fact, all the steps concerning the data analysis involve the use of computer technology as calculation software (such as IDL, Matlab, etc.) and programming languages (such as C ++, Java, Python). The large amount of data available today thanks to information technology requires specific skills in order to be managed as efficiently as possible. Indeed, data research and extraction require knowledge of the various formats. The data are structured and stored in files or database tables with particular formats. XML, JSON, or simply XLS or CSV files are now the common formats for storing and collecting data, and many applications also allow their reading and managing data stored on them. For the extraction of data contained in a database, things are not so immediate, but you need to know SQL query language or use software specially developed for the extraction of data from a given database. Moreover, for some specific types of data research, the data are not available in a pre-treated and explicit format, but are present in text files (documents, log files) or in web pages, shown as charts, measures, number of visitors, or HTML tables that require specific technical expertise for the parsing and the eventual extraction of these data ( Web Scraping ).