Python Introduction

Download as pdf or txt
Download as pdf or txt
You are on page 1of 38

Introduction to Business Analytics

Copyright © LEARNXT
Introduction to Python Programming

Introduction to Python and Python IDE


Copyright © LEARNXT
Objectives
At the end of this topic, you will be able to understand and explain:
 Understand the basics of the Python programming language

 Explain why Python is preferred for data science applications

 Explain the process of installing an IDE for Python

 Understand the basics of working with Jupyter notebooks

Copyright © LEARNXT
Introduction to Python
Copyright © LEARNXT
Python - Introduction
 Python is a high-level language with which one can do a lot with relatively little code

 Open source and free

 Supposedly easier to learn than its main competitor, Perl

 Popular among high-level languages for data science applications

 Robust support for object-oriented programming

 Support for integration with other languages

 Companies use Python to discover insights from data

Copyright © LEARNXT
Python - Introduction
 Python is an interpreted, object-oriented, high-level programming language with dynamic
semantics

 Python's simple, easy to learn syntax emphasizes readability and therefore reduces the cost of
program maintenance

 Python supports modules and packages, which encourages program modularity and code
reuse

Copyright © LEARNXT
What can Python Do?
 Python can be used on a server to create web applications

 Python can be used alongside software to create workflows

 Python can connect to database systems. It can also read and modify files

 Python can be used to handle big data and perform complex mathematics

 Python can be used for rapid prototyping, or for production-ready software development

Copyright © LEARNXT
Why Python is Preferred for Data
Science
Copyright © LEARNXT
Python Preference
 Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc)

 Python has a simple syntax similar to the English language

 Python has syntax that allows developers to write programs with fewer lines than some other
programming languages

 Python runs on an interpreter system, meaning that code can be executed as soon as it is
written. This means that prototyping can be very quick

 Python can be treated in a procedural way, an object-oriented way or a functional way

Copyright © LEARNXT
Difference Between R and Python
R Python
Primarily developed to perform statistical and data analysis Provides a general approach to Data Science for deployment
and production
Built by statisticians and encompasses their specific language General-purpose language with an easy-to-understand syntax

Used primarily in academics and research and is great for Used by programmers for data analysis / statistical techniques
exploratory data analysis and for data science applications
~12000 packages available in CRAN. You can find a library for Provides cutting-edge API for AI / ML. Most of the data science
whatever analysis you want to perform job can be done with 5 libraries: Numpy, Pandas, Scipy, Scikit-
learn and Seaborn
A tool to carry out statistical and data analysis A tool to deploy and implement machine learning at a large-scale

Heavily dependent on libraries Python codes are easier to maintain and more robust
Mostly run locally Can be integrated with apps and production environment

Uses RStudio for IDE Jupyter Notebook and Spyder are most popular IDEs
High learning curve Not as many libraries as R

Copyright © LEARNXT
R Vs Python

Copyright © LEARNXT
Python Preference
 Best tool for Machine Learning integration and deployment at large scale

 Includes great libraries to manipulate matrix or to code the algorithms

 Gained popularity for its code readability, speed, and many functionalities

 Many Python IDEs to choose from which drastically reduce the overhead of organizing code,
output, and notes files

Copyright © LEARNXT
Python Preference
 Can be well-integrated with apps in a production environment

 Statistical gap between R and Python are getting closer and most of the job can be done by
both languages

 Advantage of higher speed and interactivity with Jupyter notebooks

Copyright © LEARNXT
Installing IDE for Python
Copyright © LEARNXT
IDE
 A code editor is a tool that is used to write and edit code. They are usually lightweight and can
be great for learning

 However, once your program gets larger, it is better to use an IDE to test and debug your code

 IDE refers to Integrated Development Environment

 An IDE understands the code much better than a text editor

 It usually provides features such as build automation, code linting, testing and debugging

 Thus, IDEs can significantly speed up your work. The downside is that IDEs can be
complicated to use

Copyright © LEARNXT
Running Python
 Two ways to run Python programs

 Using Shell

 Using Integrated Development Environment (IDE). Examples:

 Jupyter

 Spyder

 PyCharm

 Jupyter Notebook is an open-source web application that you can use to create and share
documents that contain live code, equations, visualizations, and text

 The name, Jupyter, comes from the core supported programming languages that it supports:
Julia, Python, and R
Copyright © LEARNXT
IPython Shell
 Command shell for interactive computing in multiple programming languages

 Originally developed for the Python programming language

 Offers rich media, shell syntax, tab completion and history

 Python Script

 Text files using .py

 Python commands can be used

 Like typing in IPython Shell

Copyright © LEARNXT
Anaconda Distribution
 Anaconda is a conditional free and open-source distribution of the Python and R programming
languages for scientific computing that aims to simplify package management and deployment

 Distribution includes data-science packages suitable for Windows, Linux, and macOS

 It is developed and maintained by Anaconda, Inc., which was founded by Peter Wang and
Travis Oliphant in 2012

 It is also known as Anaconda Distribution or Anaconda Individual Edition, while other products
from the company are Anaconda Team Edition and Anaconda Enterprise Edition, both of which
are not free

Copyright © LEARNXT
Python IDE

Copyright © LEARNXT
IDEs for Python Within Anaconda Navigator

Copyright © LEARNXT
Install Anaconda – Jupyter Notebook
 Install Anaconda

 Open Command Prompt / Terminal or Use Anaconda Navigator

 Run Jupyter Notebook

Copyright © LEARNXT
Installing Anaconda – Jupyter Notebook
 Install Python through the anaconda distribution https://www.anaconda.com/distribution/

Copyright © LEARNXT
Install Anaconda – Jupyter Notebook
 Download the Python 3.8 version (or the latest available version) for Windows / Mac / Linux as
applicable

Copyright © LEARNXT
Installing Anaconda – Jupyter Notebook
 Open Anaconda Prompt / Terminal

 Type Jupyter notebook

Copyright © LEARNXT
Anaconda Navigator – Jupyter Notebook
 Open Anaconda Navigator

Copyright © LEARNXT
Install Anaconda – Jupyter Notebook
 Click Launch under Jupyter notebook

Copyright © LEARNXT
Jupyter Notebooks - Basics
Copyright © LEARNXT
Jupyter Notebook
 Jupyter Notebook is an open-source web application that allows you to create and share
documents that contain live code, equations, visualizations and explanatory text

Copyright © LEARNXT
Understanding the Jupyter Notebook

Copyright © LEARNXT
Create a Jupyter Notebook
 Create your first Jupyter notebook

 Print current working directory

 pwd

 'C:\\Users\\user\\python programming’

 Import the os package

 import os

Copyright © LEARNXT
Create a Jupyter Notebook
 Change the working directory

 os.chdir('D:/Jupyter Notebook/Analytic_toolkit')

 Check the working directory

 pwd

 'D:\\Jupyter Notebook\\Analytic_toolkit'

Copyright © LEARNXT
Using the Print Command
 Using the print command

 print("Hello World")

 Hello World

 Using the tab character

 print("2**2 =", "\t", 2**2)

 2**2 = 4

Copyright © LEARNXT
Using the Print Command
 print(1+3) i=1+3
 4 print(i)

 pi = 3.1415926 4

 print(pi)

 3.1415926

 message = "Hello, world"

 print(message)

 Hello, world

Copyright © LEARNXT
Summary
 Python is an interpreted, object-oriented, high-level programming language with dynamic
semantics

 Python provides a general approach to Data Science for deployment and production while R
was primarily developed to perform statistical and data analysis

 It gives the advantage of higher speed and interactivity with Jupyter notebooks

 Integrated Development Environment (IDE) usually provides features such as build


automation, code linting, testing and debugging

 Jupyter Notebook is an open-source web application that you can use to create and share
documents that contain live code, equations, visualizations, and text

Copyright © LEARNXT
Additional Resources
 McKinney, W. (2013). Python for data analysis. O'Reilly Media.

 Lutz, M. (2013). Learning Python: Powerful object-oriented programming. O'Reilly Media.

 Summerfield, M. (2010). Programming in Python 3: A complete introduction to the Python


language. Pearson Education India.

 Matthes, E. (2019). Python crash course: A hands-on, project-based introduction to


programming (2nd ed.). No Starch Press.

 Beazley, D., & Jones, B. K. (2013). Python cookbook: Recipes for mastering Python 3. O'Reilly
Media.

Copyright © LEARNXT
e-References
 Welcome to Python.org. (n.d.). Python.org. https://www.python.org

 Introduction to Python. (n.d.). W3Schools Online Web Tutorials.

https://www.w3schools.com/python/python_intro.asp

Copyright © LEARNXT 36
Any Questions?

Thank you
Copyright © LEARNXT
Copyright © LEARNXT

You might also like