Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
26 views

Python Week+1 New

The document discusses the need for Python and its basic features. It then covers popular Python packages like NumPy, Pandas, Scikit-Learn and libraries like Matplotlib and Seaborn. It also discusses steps to install Python and the use of Jupyter Notebook.

Uploaded by

Manali Gurudatta
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Python Week+1 New

The document discusses the need for Python and its basic features. It then covers popular Python packages like NumPy, Pandas, Scikit-Learn and libraries like Matplotlib and Seaborn. It also discusses steps to install Python and the use of Jupyter Notebook.

Uploaded by

Manali Gurudatta
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 44

Introduction to

PYTHON
Table of Content
• Why Python
• Applications of Python
• Python and its features
• Packages overview
– NumPy
– Pandas
– Scikit Learn
– Matplotlib
– Seaborn
– TensorFlow
• Installation steps
• Jupyter Notebook for Python and shortcuts
Python’s Benevolent Dictator For Life

“Python is an experiment in how much freedom programmers need. Too much freedom and
nobody can read another's code; too little and expressiveness is endangered.”
- Guido van Rossum
Why Python

• Easy to understand
• Free and open source
• Huge community support
• Robust standard libraries
• Wide range of applications
• Fast edit-test-debug cycle
• Portable
• Scalable
Application Of Python

Software
development

AI/ML & Data science &


visualization analytics

GUI
Web
Game development
development
Application Of Python

Large section of YouTube video sharing system is written in Python.

NASA uses Python to perform many specific tasks.

Web search system uses Python.

Server & Client software of Dropbox storage use Python.

Peer to peer file sharing system started with Python.


Python & Its Features

• Object oriented programming

• Interpreted language
• High-level programming
• Dynamic semantics

• High-level built in data structures


• Automatic garbage collection
Python Built-in Data Types

Boolean Bool 0,1,True,False

‘python’
Text Str
“python”
int, float,
10, 10.67, 10+2j
complex
Numeric
List [1,”A”,[2,4]]
Python data
types Sequence
Tuple (1,2,3,4)

Mapping {“name” : “python”,


Dict
”number”:1}

Set Set {1,2,3,4}

Binary bytes b"Hello"


Python Operators
Arithmetic operators +,-
=, Assignment operators
+=
Relational operators <,>
an
d, Logical operators
Is, or
Identity operators is
not In,
not Membership operators
in
Bitwise operators &,^
Python Tokens
Small units of the programming language

Keywords

Punctuators Tokens Identifiers

Operators Literals
List, Tuples, Dictionary & Set

Apart from data types like int, string, float Python has the
Tuples Sets
below data types which are very useful for data science -

List - Lists are used to store multiple items in a single ( ) { }


variable.
[ ] { }

Tuples - Tuples are used to store multiple items in a single


variable
Lists Dictionaries
Dictionaries - Dictionaries are used to store data values in
key : value pairs. A dictionary is a collection which is
ordered*, changeable and do not allow duplicates

Set - A Set is an unordered collection data type that is


iterable, mutable, and has no duplicate elements.
Packages Overview

• A Python package usually consists of Pandas

several modules.
NumPy
• Has Build-in modules & Open source
modules. Scikit Learn

• NumPy, Pandas, Scikit Learn,


Matplotlib, Seaborn, SciPy, TensorFlow, Matplotlib

Keras, and many more.


Seaborn
OPEN SOURCE PACKAGES
1. NumPy

• Adds support for large, multi-dimensional


arrays and matrices, along with a large
collection of high-level mathematical
functions to operate on these arrays.

• Open source library


2. Pandas
• Mainly used for structured data operations and manipulations.
• Offer powerful data processing capabilities, open source library.

Reading various
Manipulating the
forms Datasets Reshaping Datasets
data
(CSV, Excel, etc)

Splitting and Merging,


Pandas
modifying the concatenating
Datasets Capabilities Datasets

Handling missing Grouping and Indexing and


data filtering data Ranking
3. Scikit Learn
• Contains a huge number of Machine
Learning algorithms and other key
performance-related libraries
– Regression
– Classification
– Clustering
– Model Selection
– Dimensionality reduction and many
more
4. Matplotlib
• Plotting library for the Python programming language and its numerical mathematics extension NumPy.
• Most of the Matplotlib utilities lies under “pyplot” submodule.
5. Seaborn
• Visualization library for statistical graphics plotting in Python.
• Built on the top of Matplotlib.
• Closely integrated to the data structures from Pandas.
• Seaborn divides plot into the below categories
 Relational plots
 Categorical plots
 Distribution plots
 Regression plots
 Matrix plots
 Multi plot grids
• Examples: displot, boxplot, countplot, etc.
5. Seaborn
Python Installation – Need For Editor

PYTHON IDEs (Integrated Development Environment)


• A text editor helps to automate the tasks and enhance
the productivity and efficiency of the developer.
• Why IDE ? : Jupyter
– Provides an editor designed to handle code (with, for
example, syntax highlighting and auto-completion).
IDLE
– Provides build, execution, and debugging tools.
– Some form of source control.
Python Installation – Anaconda Distribution
Anaconda distribution comes with over 250 packages automatically installed, and over 7,500
additional open-source packages can be installed from PyPI as well as the conda package.

Anaconda Individual Edition links:

1. Anaconda 5.2 For Linux Installer - https://www.anaconda.com/download/#linux


2. Anaconda 5.2 For macOS Installer - https://www.anaconda.com/download/#macos
3. Anaconda 5.2 For Windows Installer - https://www.anaconda.com/download/#windows

(You need to download the version compatible with your OS.)


Anaconda Navigator
Jupyter Notebook For Python

• An open source web application that you can use to create and share
documents that contain live code, equations, visualizations, and text.
• Anaconda navigator comes with Jupyter notebook.
Jupyter Notebook Shortcuts
Summary

• Discussed need for python


• Basic features of python
• Variables and operators in python

• Packages in Python
• Editor and Jupyter
Numpy & Pandas

• NumPy in Python
• NumPy arrays
• Functions to create array
• NumPy Matrix
• Indexing and slicing
• Selection techniques
• Pandas in Python
• Series
• Dataframe
• Indexing
• Loading and saving dataframes
• Summary
Numpy

Arithmetic
• Installation – conda install numpy operations

• Usually imported with alias name np


Vector/
Linear
Matrix
Algebra
operations
Uses of
NumPy

Random
module Broad-
casting

In built
functions
Functions To Create Specific Arrays

• zeros()
• ones()
• empty()
• eye()
• identity()
• empty_like()
• zeros_like()
• onces_like()
• asarray()
• full()
• full_like()
Numpy Matrix

• Designated 2 dimensional array


• Has matrix multiplication and matrix squared operators
• Returns a matrix of same dimension (2-D)
Difference Between Numpy ARRAY & Numpy Matrix

Difference NumPy N-D Array Object NumPy Matrix Object

Dimensionality Multi-dimensional 2 Dimensional


Multiplication with * Element by element Dot product
operator multiplication
Multiplication with * * Element wise squared operation Matrix multiplication
operator
Class Base class Derived class (Inherits from N-d
array)
Inverse method Do not have inverse method (.I) Have inverse (.I) method
Usage/ Demand Highly used No longer recommended to use

NOTE: Matrix class is deprecated for future. Instead use Numpy arrays
Indexing And Slicing

Field
access

Slicing
Indexing
Integer
Advance
indexing
Boolean
Numpy Selection Techniques

• where()
• choose()
• select()
• random.choice()
• invert()
Common Numpy Functions
Function Description

np.array() To create an array

np.arange() Return evenly spaced values within a given interval

np.linspace() Return evenly spaced numbers over a specified interval

np.zeros() To create an array of zeros

np.ones() To create an array of ones

np.transpose() Permute array dimensions


Common Numpy Functions
Function Description

np.random.rand() To create an array of specified shape filled with random values

np.random.randint() Return random integers from low (inclusive) to high (exclusive)

np.random.randn() Return a sample (or samples) from the “standard normal” distribution.

np.concatenate() Concatenate two arrays

np.save() Save an array to a binary file in .npy format.

np.savez() Save several arrays into a single file in uncompressed .npz format.
Pandas
Pandas In Python

• Build on top of NumPy Reading


Reshaping
Datasets
various Manipulati
• Supports data manipulation forms ng the data
• Open source Datasets

• Stable release – 1.3.0 / 2 Splitting


and Pandas Merging,
• Offer powerful data processing modifying
Capabilities concatenati
the ng Datasets
capabilities Datasets
• Usually imported with alias
name pd Handling Grouping Indexing
missing and and
data filtering Ranking
data
Pandas Series
• One dimensional array which can
hold any data type
• Supports various methods:
• append()
• abs()
• add()
• agg()
• describe()
• all()
• apply()
• copy()
• count()
Pandas Dataframe
• 2 D tabular data structure
• Similar to SQL table
• Most widely used Pandas
object

• Like Series, input can be


anything ( ndarray,
dictionary, list, series, etc.)
Common Pandas Functions
Function Description

df.value_counts() To get count of some attributes

df.unique() To get unique values

df.dtype To get the data types

df.shape To get the shape (number or rows and columns)

df.head() To get the top rows

df.describe() To get the quick statistic summary


Pandas Indexing

• Indexing can be done


through .iloc[ ] , .loc[ ]
• .loc[ ] uses label to select data
• .iloc[ ] uses position (integer location)
to select data
Loading And Saving Dataframe
• Pickle : used for saving and loading
Dataframe

• df.to_pickle(filename)
• pd.read_pickle(filename)
• csv file : can save Dataframe using
csv file

• df.to_csv(filename)
• pd.read_csv(filename)
Summary
• Discussed Numpy arrays
• Functions to create numpy arrays
• Difference between numpy array and numpy matrix
• Indexing and slicing
• Numpy selection methods
• Pandas in Python
• Series and methods associated with it
• Dataframe and methods associated with it
• Indexing in Dataframe
• Dataframe loading and saving
Thank you!
Happy Learning :)

You might also like