Python for Data Science
Jamil Saudagar
Jamil Saudagar 1 of 75
Introduction and History
• Python was developed by Guido Van Rossum in the year 1991 at the Center for Mathematics and Computer
Science
• The name Python was picked up from a T.V. show Monty Python’s Flying Circus.
• The first working version was ready by early 1990 and was released for the public on 20th February 1991.
• It is an open source software. It combines the functionality of C with object oriented approach of Java
• Features of Python
• Simple and Easy to learn
• Dynamically Typed i.e. An assignment statement binds a name to an object
• Platform independent
• Huge Library
• Does not use a compiler but uses an interpreter to execute instructions
Jamil Saudagar 2 of 75
Introduction and History
• Execution of a Python program
Compile PVM
Source Byte Machine
Code Code Code
Jamil Saudagar 3 of 75
Introduction and History
Byte Code example in Jupyter Notebook
• There are two ways to distribute the created software in Python
• The first is to distribute the .pyc files to the user. The user will install the Python Virtual machine and
execute.
• The second is to convert the .pyc files (alongwith libraries and PVM) into a .exe file (frozen binaries).
• Third party software like py2.exe is used to create frozen binaries (For Windows)
• Third party software like pyinstaller.exe or Freeze is used to create frozen binaries (For Unix / Linux)
Jamil Saudagar 4 of 75
Python Installation
• Open your Browser and go to https://www.python.org/downloads/
• Download the appropriate version for your Operating System.
• Once the installation file is downloaded; click on the executable file and select appropriate options at the
Python installation prompt. When in doubt; select the default choice.
• Remember to add python.exe to the default path. This way python can run from any of the folders.
• You may also want to install (https://www.anaconda.com/distribution/ ). Here too, download
and during the installation select appropriate choices.
Jamil Saudagar 5 of 75
Different methods to start a Python session
• Windows Start > Python > Python 3.7 (64-bit)
• Windows Start > Python > IDLE (Python 3.7 64 bit)
Jamil Saudagar 6 of 75
Different methods to start a Python session
• Windows Start > Anaconda3 > Anaconda Navigator
• Windows Start > Anaconda3 > Anaconda Prompt (We are going to use this method)
• Windows Start > Anaconda3 > Jupyter Notebook
Jamil Saudagar 7 of 75
Getting Started
• The coding environment
• Click on the Anaconda prompt to open a command window
• Navigate to the project folder where you would like to save the code files.
• At the prompt (>) type jupyter notebook.
• A session will open up in the default browser as shown below :
Jamil Saudagar 8 of 75
Getting Started
• Click on New > Python3 to start a new session (Please remember Python is a case sensitive language)
• Basic Mathematical Operations
• In a new cell type the following statements :
• 2 + 3 and hit <Shift + Enter>
• 10 – 4 and hit <Ctrl + Enter>
• 10 * 4 and hit <Shift + Enter>
• 10 / 4 and hit <Shift + Enter>
• 10 // 4 and hit <Shift + Enter>
• 5 % 2 and hit <Shift + Enter>
• 2 ** 5 and hit <Shift + Enter>
• 2 + 5 * (7-3)
• Type help() at the prompt to get into help mode, pressing enter at the help prompt will help us exit the help
window
Jamil Saudagar 9 of 75
Getting Started
• Input and Output using the print() and input() statements
• print('Hello World !!!')
• print("He isn't in the best of his moods")
• print("The sum of 2 and 5 is = ", 2+5)
•
• Commenting statements / text
Jamil Saudagar 10 of 75
Getting Started
• The input() statement
• Keyboard Shortcuts
• Press <Esc + H> to get a list of shortcuts
• Markdowns
• Markdowns help us add a title (heading) to our cell(s). We can create headings from H1 to H6
• Write a program to find the area of a triangle
Jamil Saudagar 11 of 75