Python For Data Analysis:
A Beginners Guide to Learn Data Analysis with Python Programming.
Dr. John Hush
Table of Contents
Introduction
Congratulations on purchasing Python For Data Analysis and thank you for doing so.
There are plenty of books on this subject on the market, thanks again for choosing this one! Every effort was made to ensure it is full of as much useful information as possible, please enjoy!
Python is a high-level object-oriented language (English, Very High-Level Language) dynamic typing, strong, interpreted and interactive.
Features
Python has a clear and concise syntax that promotes the readability of source code, making the language more productive.
The language includes a number of high-level structures (lists, dictionaries, date/time, complexes, and more) and a large collection of ready-to-use modules, as well as third party frameworks that can be added. It also has features found in other modern languages such as generators, introspection, persistence, metaclass and test units. Multiparadigm, the language supports modular and functional programming as well as object-orientation. Even the basic types in Python are objects. The language is interpreted bytecode by the Python virtual machine, making the code portable. This makes it possible to compile applications on one platform and run on other systems or run straight from source code.
Python is open-source software (licensed under the General Public License (GPL)) but less restrictive, allowing Python to even be incorporated into proprietary products). The language specification is maintained by Python Software Foundation (PSF).
In addition to being used as the main language in systems development, Python is also widely used as a scripting language in many software, allowing you to automate tasks and add new features, including BrOffice.org, PostgreSQL, Blender, GIMP, and Inkscape.
You can integrate Python with other languages, such as C and Fortran. In general terms, language has many similarities with other dynamic languages such as Perl and Ruby.
Chapter 1 - Introduction to Data Analysis
For the Windows platform, just run the installer. For other platforms, such as Linux systems, Python is usually already part of the system, but in some cases, it may be necessary to compile and install the interpreter from source files.
There are also Python implementations for.NET (IronPython), JVM (Jython), and Python (PyPy).
Running Programs
Python program example:
A list of musical instruments = [Bass, 'Drums', 'Guitar']
For each name in the instrument list:
show name of musical instrument print instrument
Output:
Low
Drums
Guitar
In the example, "instruments" is a list containing the items "bass", "drums" and "guitar". Already "instrument" is a name that corresponds to each of the list items as the loop is executed.
Source files are usually identified by the extension .py and can be executed directly by the interpreter:
python apl.py
This will launch the apl.py program. On Windows, the file extensions .py, .pyw, .pyc and .pyo are automatically associated with Python during installation, so just click on the file to execute. ".Pyw" files are executed with an alternate version of the interpreter that does not open the console window.
Dynamic Typing
Python typing is strong, meaning the interpreter checks to see if the operations are valid and does not automatically constrain incompatible types. To perform the operation between non-compliant types, you must explicitly convert the type of the variable or variables before the operation.
Compilation and Interpretation
By default, the interpreter compiles the code and stores the bytecode on disk so that the next time you run it, you don't have to compile the program again, reducing the load time on execution. If the source files are changed, the interpreter will be responsible for regenerating bytecode automatically, even using the interactive shell. When a program or module is invoked, the interpreter performs code analysis, converts to symbols, compiles (if there is no updated bytecode on disk), and runs on the Python virtual machine.
The bytecode is stored in files with the extension ".pyc" (bytecode normal) or ".pyo" ( bytecode optimized). The bytecode can also be packaged together with the interpreter into an executable for easy application deployment, eliminating the need to install Python on each computer.
Interactive Mode
The Python interpreter can be used interactively, where lines of code are typed at a prompt similar to the operating system shell.
To evoke interactive mode just run the interpreter (if it is in path ):
Chapter 2 - Python for Data Analysis
Interactive mode is a distinguishing feature of the language, as it is possible to test and modify code snippets before including code in programs, extract and convert data, or even analyze the state of objects in memory, among other possibilities.
In addition to Python's traditional interactive mode, there are other programs that work as alternatives, with more sophisticated interfaces (such as PyCrust):
Tools
There are many development tools for Python, such as IDEs, editors, and shells (which take advantage of Python's interactive capabilities).
Integrated Development Environments (IDEs) are software packages that integrate various development tools into a consistent environment to increase developer productivity. Generally, IDEs include features such as syntax highlight (color-coded according to language syntax), code browsers, integrated shell and code completion (the editor provides possible ways to complete the text he can identify).
Python-supporting IDEs include:
PyScripter
SPE (Stani's Python Editor)
Eric
PyDev (plug-in for the Eclipse IDE).
There are also specialized program code text editors, which have features such as syntax coloring, export to other formats, and text encoding conversion.
Shell is the name given to interactive command execution environments, which can be used to test small portions of code and for activities such as data crunching (extraction of information of interest from masses of data and subsequent translation to other formats).
In addition to the standard Python Shell itself, there are others available:
PyCrust (graph).
Ipython (text).
Wrappers are utilities that are used to build executables that include bytecode, interpreter, and other dependencies, allowing the application to run on machines without Python installed, which makes it easier to distribute programs.
Python wrappers include:
Py2exe (Windows only).
cx_Freeze (portable).
Frameworks are collections of software components (libraries, utilities, and others) that are designed for use by other systems.
Culture
The Python user community has created some expressions to refer to language-related subjects. In this jargon, the term Pythonic is used to indicate that something is compatible with Python's design assumptions, and Unpythonic means the opposite. The language user is called from Pythonist.
The project goals were summarized by Tim Peters in a text called Zen of Python, which is available in Python itself through the command:
import this
The text emphasizes the pragmatic stance of the Benevolent Dictator for Life (BDFL), as Guido is known in the Python community.
Proposals for language improvement are called Python Enhancement Proposals (PEPs), which also serve as a reference for new features to be implemented in the language.