You are on page 1of 98

Introduction to PYTHON

Python is a very popular general-purpose interpreted,


interactive, object-oriented, and high-level programming
language

Python supports multiple programming paradigms,


including Procedural, Object Oriented and Functional
programming language. Python design philosophy
emphasizes code readability with the use of significant
indentation
 Python is Open Source which means its available free of cost.
 Python is simple and so easy to learn
 Python is versatile and can be used to create many different things.
 Python is much in demand and ensures high salary
 Python is Interpreted − Python is processed at runtime by the interpreter.
You do not need to compile your program before executing it. This is similar
to PERL and PHP.
 Python is Interactive − You can actually sit at a Python prompt and interact
with the interpreter directly to write your programs.
 Python is Object-Oriented − Python supports Object-Oriented style or
technique of programming that encapsulates code within objects.
 Python is a Beginner's Language − Python is a great language for the
beginner-level programmers and supports the development of a wide range of
applications from simple text processing to WWW browsers to games.
 Applications of Python
 The latest release of Python is 3.x. As mentioned before, Python is one of the
most widely used language over the web. I'm going to list few of them here:
 Easy-to-learn − Python has few keywords, simple structure, and a clearly
defined syntax. This allows the student to pick up the language quickly.
 Easy-to-read − Python code is more clearly defined and visible to the eyes.
 Easy-to-maintain − Python's source code is fairly easy-to-maintain.
 A broad standard library − Python's bulk of the library is very portable and
cross-platform compatible on UNIX, Windows, and Macintosh.
 Interactive Mode − Python has support for an interactive mode which allows
interactive testing and debugging of snippets of code.
 Portable − Python can run on a wide variety of hardware platforms and has the same
interface on all platforms.
 Extendable − You can add low-level modules to the Python interpreter. These
modules enable programmers to add to or customize their tools to be more efficient.
 Databases − Python provides interfaces to all major commercial databases.
 GUI Programming − Python supports GUI applications that can be created and ported
to many system calls, libraries and windows systems, such as Windows MFC,
Macintosh, and the X Window system of Unix.
 Scalable − Python provides a better structure and support for large programs than
shell scripting.
Working with data types and variables.

 Python List:In this tutorial, we'll learn everything about Python lists: creating lists, changing list
elements, removing elements, and other list operations with the help of examples.
 # empty list
 my_list = []
# list of integers
my_list = [1, 2, 3]
# nested list
my_list = ["mouse", [8, 4, 6], ['a']]
# list with mixed data types
 my_list = [1, "Hello", 3.4]
 List Index
 We can use the index operator [] to access an item in a list. In Python, indices start at 0. So, a
list having 5 elements will have an index from 0 to 4.
Working with data types and variables

 In this article, you'll learn everything about Python tuples.


More specifically, what are tuples, how to create them, when
to use them and various methods you should be familiar with.
 Tuples are used to store multiple items in a single variable.
 A tuple is a collection which is ordered and unchangeable.
 To determine how many items a tuple has, use the len()
function:
 # Different types of tuples
# Different types of tuples

 # Empty tuple
 my_tuple = ()
 print(my_tuple)

 # Tuple having integers


 my_tuple = (1, 2, 3)
 print(my_tuple)
 String, int and boolean data types:

 tuple1 = ("apple", "banana", "cherry")


 tuple2 = (1, 5, 7, 9, 3)
 tuple3 = (True, False, False)
 tuple1 = ("abc", 34, True, 40, "male")
Python dictionary is an unordered collection of items. Each item of a dictionary has a key/value pair.

Working with data types and variables

 A tuple in Python is similar to a list. The difference between the two is that
we cannot change the elements of a tuple once it is assigned whereas we can
change the elements of a list.
 Python del Statement: The Python del keyword is used to delete objects. Its
syntax is:

 # delete obj_name
 del obj_name
 Python Dictionary: Python dictionary is an unordered collection of items. Each item of
a dictionary has a key/value pair.
Working with data types and variables

 Creating a dictionary is as simple as placing items inside curly braces {}


separated by commas.

 An item has a key and a corresponding value that is expressed as a pair (key:
value).
 # empty dictionary
 my_dict = {}

 # dictionary with integer keys


 my_dict = {1: 'apple', 2: 'ball'}
Dictionary

 Dictionary Items
 Dictionary items are ordered, changeable, and does not allow
duplicates.
 Dictionary items are presented in key:value pairs, and can be
referred to by using the key name.
 Dictionaries cannot have two items with the same key:
Working with numeric data.

 Integers and Floating-Point Numbers


 >>>1.0 + 2
 3.0
 Notice that the result of 1.0 + 2 is 3.0, which is a float. Anytime a float is added to a number, the result
is another float.
 To subtract two numbers, just put a - operator between them:

 >>> 1 - 1
 0
 To multiply two numbers, use the * operator:

 >>> 3 * 3
 9
Working with numeric data.

 The / operator is used to divide two numbers:

 >>> 9 / 3
 3.0
 If you want to make sure that you get an integer after dividing two numbers,
you can use int () to convert the result.
Working with string data.

 In Python, Strings are arrays of bytes representing Unicode characters Strings


in Python can be created using single quotes or double quotes or even triple
quotes.
 Strings in python are surrounded by either single quotation marks, or double
quotation marks.

 'hello' is the same as "hello".

 Python does not have a character data type, a single character is simply a
string with a length of 1
Unit 2:classes in python

 A class is a user-defined blueprint or prototype from which objects are created. Classes
provide a means of bundling data and functionality together. Creating a new class
creates a new type of object, allowing new instances of that type to be made. Each class
instance can have attributes attached to it for maintaining its state.
 Class Definition Syntax:

 class ClassName:
 # Statement

 Object Definition Syntax:


 obj = ClassName()
 print(obj.atrr)
The __init__() Function

 The examples above are classes and objects in their simplest form,
and are not really useful in real life applications.
 To understand the meaning of classes we have to understand the
built-in __init__() function.
 All classes have a function called __init__(), which is always executed
when the class is being initiated.
 Use the __init__() function to assign values to object properties, or
other operations that are necessary to do when the object is being
created:
The __init__() Function

 Create a class named Person, use the __init__() function to assign values for name and age:

 class Person:
 def __init__(self, name, age):
 self.name = name
 self.age = age

 p1 = Person("John", 36)

 print(p1.name)
 print(p1.age)
2.1 OOPS Concepts.

 Main Concepts of Object-Oriented Programming (OOPs)


 Class
 Objects
 Polymorphism
 Encapsulation
 Inheritance
 Data Abstraction
 Class 
 A class is a collection of objects. A class contains the blueprints or the
prototype from which the objects are being created
 The object is an entity that has a state and behavior associated with it. It
may be any real-world object like a mouse, keyboard, chair, table, pen, etc.
2.2 Classes and objects.

 A class has some data which describes the state of the objects and the
functions perform different operations. These operations are mainly
performed on the data of the object.

 class SuperHuman:
 # attribute init
 name = "Bruce Wayne"
 power = "super strong"
 def tagline(self):
 print(f"My name is: {self.name}", f"and my character is {self.power}")
Classes and objects.

 # Driver code
 # initalising object
 bat = SuperHuman()
 bat.tagline()
 OutputMy name is: Bruce Wayne and my character is super strong
Object in Python

 We can define an object as an instance of a class. The class only describes


the details of the object or the blueprint of the object.
 The creation of a new object or instance is called instantiation.

 Different data types like integer, string, float, array, dictionaries, all are
objects.
Object in Python

 Insert a function that prints a greeting, and execute it on the p1 object:


 class Person:
  def __init__(self, name, age):
    self.name = name
    self.age = age

  def myfunc(self):
    print("Hello my name is " + self.name)

p1 = Person("John", 36)
p1.myfunc()
Constructor

 Constructors are generally used for instantiating an object


 Syntax of constructor declaration :

 def __init__(self):
 # body of the constructor
 Types of constructors :

 default constructor: The default constructor is a simple constructor which doesn’t


accept any arguments
 parameterized constructor: constructor with parameters is known as
parameterized constructor.
parameterized constructor

 # parameterized constructor
 def __init__(self, f, s):
 self.first = f
 self.second = s

 def display(self):
 print("First number = " + str(self.first))
 print("Second number = " + str(self.second))
 print("Addition of two numbers = " + str(self.answer))

# parameterized constructor

 ef calculate(self):
 self.answer = self.first + self.second
 # creating object of the class
 # this will invoke parameterized constructor
 obj = Addition(1000, 2000)
 # perform Addition
 obj.calculate()

 # display result
 obj.display()
parameterized constructor

 Output :

 First number = 1000


 Second number = 2000
 Addition of two numbers = 3000
Default constructor

 class GeekforGeeks:

 # default constructor
 def __init__(self):
 self.geek = "GeekforGeeks"

 # a method for printing data members


 def print_Geek(self):
 print(self.geek)
Default constructor

 # creating object of the class


 obj = GeekforGeeks()

 # calling the instance method using the object obj


 obj.print_Geek()
 Output :

 GeekforGeeks
Destructors

 Destructors are called when an object gets destroyed. In Python, destructors


are not needed as much as in C++ because Python has a garbage collector that
handles memory management automatically.
 The __del__() method is a known as a destructor method in Python.
 Syntax of destructor declaration :
 def __del__(self):
 # body of destructor

Destructors

 class Employee:
 # Initializing
 def __init__(self):
 print('Employee created.')
 # Deleting (Calling destructor)
 def __del__(self):
 print('Destructor called, Employee deleted.')
 obj = Employee()
 del obj
 Employee created.
 Destructor called, Employee deleted.
Data hiding, Creating classes

 when we do not want to give out sensitive parts of our code implementation
and this is where data abstraction came.
 An Object is an instance of a Class. A class is like a blueprint while an
instance is a copy of the class with actual values
 When an object of a class is created, the class is said to be instantiated. All
the instances share the attributes and the behavior of the class
Data hiding, Creating classes
Inheritance

Inheritance is the capability of one class to derive or inherit the properties from another class. 
The new class is called derived (or child) class and the one from which it inherits is called the base (or parent) class.
class BaseClass:
Body of base class
class DerivedClass(BaseClass):
Body of derived clas
Single Inheritance
Single Inheritance

 class Parent:
 def func1(self):
 print("This function is in parent class.")
 # Derived class
 class Child(Parent):
 def func2(self):
 print("This function is in child class.")
 # Driver's code
 object = Child()
 object.func1()
 object.func2()
Multiple Inheritance

 A class can be derived from more than one base class in Python, similar to C+
+. This is called multiple inheritance.
 class Base1:
 pass

 class Base2:
 pass

 class MultiDerived(Base1, Base2):


 pass
Multiple Inheritance

 class Class1:
 def m(self):
 print("In Class1")

 class Class2(Class1):
 def m(self):
 print("In Class2")

Multiple Inheritance

 class Class3(Class1):
 def m(self):
 print("In Class3")
 class Class4(Class2, Class3):
 pass
 obj = Class4()
 obj.m()
 Output:
In Class2
Multilevel Inheritance
Multilevel Inheritance

 # Python program to demonstrate


 # multilevel inheritance

 # Base class
 class Grandfather:
 def __init__(self, grandfathername):
 self.grandfathername = grandfathername
 # Intermediate class
 class Father(Grandfather):
 def __init__(self, fathername, grandfathername):
 self.fathername = fathername
Multilevel Inheritance

 # invoking constructor of Grandfather class


 Grandfather.__init__(self, grandfathername)

 # Derived class
 class Son(Father):
 def __init__(self, sonname, fathername, grandfathername):
 self.sonname = sonname
Multilevel Inheritance

 # Driver code
 s1 = Son('Prince', 'Rampal', 'Lal mani')
 print(s1.grandfathername)
 s1.print_name()
 Output:
 Lal mani
 Grandfather name : Lal mani
 Father name : Rampal
 Son name : Prince
Multilevel Inheritance

 # invoking constructor of Father class


 Father.__init__(self, fathername, grandfathername)

 def print_name(self):
 print('Grandfather name :', self.grandfathername)
 print("Father name :", self.fathername)
 print("Son name :", self.sonname)

 # Driver code
 s1 = Son('Prince', 'Rampal', 'Lal mani')
 print(s1.grandfathername)
 s1.print_name()
 Output:
 Lal mani
 Grandfather name : Lal mani
 Father name : Rampal
 Son name : Prince
Hierarchical Inheritance:

 Hierarchical Inheritance:
 When more than one derived class are created from a single base this type of
inheritance is called hierarchical inheritance. In this program, we have a
parent (base) class and three child (derived) classes.
Hierarchical Inheritance:

 # Python program to demonstrate


 # Hierarchical inheritance
 # Base class
 class Parent:
 def func1(self):
 print("This function is in parent class.")
 # Derived class1
 class Child1(Parent):
 def func2(self):
 print("This function is in child 1.")
class Child2(Parent):
def func3(self):
print("This function is in child 2.")

# Driver's code
object1 = Child1()
object2 = Child2()
object1.func1()
object1.func2()
object2.func1()
object2.func3()
 Output:
 This function is in parent class.
 This function is in child 1.
 This function is in parent class.
 This function is in child 2.
Hybrid Inheritance:

 Hybrid Inheritance:
 Inheritance consisting of multiple types of inheritance is called hybrid
inheritance.
Hybrid Inheritance:

 class School:
 def func1(self):
 print("This function is in school.")
 class Student1(School):
 def func2(self):
 print("This function is in student 1. ")
 class Student2(School):
 def func3(self):
 print("This function is in student 2.")
Hybrid Inheritance:

 class Student3(Student1, School):


 def func4(self):
 print("This function is in student 3.")
 # Driver's code
 object = Student3()
 object.func1()
 object.func2()
 Output:
This function is in school.
 This function is in student 1.
Polymorphism with Inheritance

 Polymorphism in python defines methods in the child class that have the same
name as the methods in the parent class. In inheritance, the child class
inherits the methods from the parent class. Also, it is possible to modify a
method in a child class that it has inherited from the parent class.
 class Bird:
 def intro(self):
 print("There are different types of birds")
 def flight(self):
 print("Most of the birds can fly but some cannot")
Polymorphism

 class parrot(Bird):
 def flight(self):
 print("Parrots can fly")
 class penguin(Bird):
 def flight(self):
 print("Penguins do not fly")
 obj_bird = Bird()
Polymorphism

 obj_parr = parrot()
 obj_peng = penguin()

 obj_bird.intro()
 obj_bird.flight()

 obj_parr.intro()
 obj_parr.flight()

 obj_peng.intro()
 obj_peng.flight()
Polymorphism

 Output:

 There are different types of birds


 Most of the birds can fly but some cannot
 There are different types of bird
 Parrots can fly
 There are many types of birds
 Penguins do not fly
Polymorphism

 class India():
 def capital(self):
 print("New Delhi")

 def language(self):
 print("Hindi and English")

 class USA():
 def capital(self):
 print("Washington, D.C.")

Polymorphism

 def language(self):
 print("English")

 obj_ind = India()
 obj_usa = USA()
 for country in (obj_ind, obj_usa):
 country.capital()
 country.language()
Polymorphism

 output
 New Delhi
 Hindi and English
 Washington, D.C.
 English
Python Custom Exceptions

 To create a custom exception class, you define a class that inherits from the
built-in Exception class or one of its subclasses such as ValueError class:

The following example defines a CustomException class


that inherits from the Exception class:

class CustomException(Exception):
""" my custom exception class """
Example of Custom Exceptions

 # define Python user-defined exceptions


 class Error(Exception):
 """Base class for other exceptions"""
 pass
class ValueTooSmallError(Error):
 """Raised when the input value is too small"""
 pass
class ValueTooLargeError(Error):
 """Raised when the input value is too large"""
 pass
Example of Custom Exceptions

 # you need to guess this number


 number = 10
# user guesses a number until he/she gets it right
 while True:
 try:
 i_num = int(input("Enter a number: "))
 if i_num < number:
 raise ValueTooSmallError
 elif i_num > number:
 raise ValueTooLargeError
 break
Example of Custom Exceptions

 except ValueTooSmallError:
 print("This value is too small, try again!")
 print()
 except ValueTooLargeError:
 print("This value is too large, try again!")
 print()

 print("Congratulations! You guessed it correctly.")


Example of Custom Exceptions

 output
 Enter a number: 12
 This value is too large, try again!

 Enter a number: 0
 This value is too small, try again!

 Enter a number: 8
 This value is too small, try again!

 Enter a number: 10
 Congratulations! You guessed it correctly.
Iterators in Python

 Iterators in Python
 Iterators are everywhere in Python. They are elegantly implemented within for loops,
comprehensions, generators etc. but are hidden in plain sight.

 Iterator in Python is simply an object that can be iterated upon. An object which will
return data, one element at a time.

 Technically speaking, a Python iterator object must implement two special methods,
__iter__() and __next__(), collectively called the iterator protocol.

 An object is called iterable if we can get an iterator from it. Most built-in containers in
Python like: list, tuple, string etc. are iterables.
Python generators

 Python generators are a simple way of creating iterators. All the work we
mentioned above are automatically handled by generators in Python.

 Simply speaking, a generator is a function that returns an object (iterator) which we


can iterate over (one value at a time).
 Create Generators in Python
 It is fairly simple to create a generator in Python. It is as easy as defining a normal
function, but with a yield statement instead of a return statement.

 If a function contains at least one yield statement (it may contain other yield or
return statements), it becomes a generator function. Both yield and return will
return some value from a function.
Python Decorators

 Decorators in Python
 Python has an interesting feature called decorators to add functionality to an
existing code.

 This is also called metaprogramming because a part of the program tries to


modify another part of the program at compile time.
Unit-3: I/O and Error Handling In Python

 Error is a abnormal condition whenever it occurs execution of the program is


stopped.

 An error is a term used to describe any issue that arises unexpectedly


that cause a computer to not function properly. Computers can encounter
either software errors or hardware errors.
Error Handling In Python

 Errors are mainly classified into following types.


 1. Syntax Errors
 1. Syntax Errors
 2. Symantec Errors
 3.Runtime Errors
 4.Logical Errors
 22. Semantic Errors
 . Semantic Errors
Syntax errors

 Syntax errors refer to formal rules governing the construction of valid


statements in a language.

 Syntax errors occur when rules of a programming language are


misused i.e., when a grammatical rule of the language is violated.
For instance in the following program segment,
def main() colon missing
a=10
b=3
print(“ Sum is “,a+b () missing)
Semantics Error

Semantics error occur when statements are not meaningful


Semantics refers to the set of rules which give the meaning of the
statement.
For example,
Rama plays Guitar
This statement is syntactically and semantically correct and it has
some meaning.
Run time error

 A Run time error is that occurs during execution of the program. It is caused
because of some illegal operation taking place.
 For example
 1. If a program is trying to open a file which does not exists or it could
not be opened(meaning file is corrupted), results into an execution error.
 2. An expression is trying to divide a number by zero are RUN TIME
ERRORS
Logical Error

 A Logical Error is that error which is causes a program to produce


incorrect or undesired output.
for instance,
ctr=1;
while(ctr<10):
print(n *ctr)
Python Files I/O
 The simplest way to produce output is using the print statement where you can pass zero
or more expressions, separated by commas
 Reading Keyboard Input:
 Python provides two built-in functions to read a line of text from standard input,
which by default comes from the keyboard. These functions are:
 raw_input
 input
 The raw_input Function:
 The raw_input([prompt]) function reads one line from standard input and returns it as a
string (removing the trailing newline):
 str = raw_input("Enter your input: ");
 print "Received input is : ", str
3.2 Data Streams, Creating Your Own
Data Streams.
 A Streams Python application is called a Topology . You define a Topology by
specifying how it will process a stream of data.
 The Topology is submitted to the Streams instance for execution
File I/O: read, write and append

 Reading from an open file returns the contents of the file


 as sequence of lines in the program
 Writing to a file
 IMPORTANT: If opened with mode 'w', clears the existing contents of the file
 Use append mode ('a') to preserve the contents
 Writing happens at the end
 Files are named locations on disk to store related information. They are used
to permanently store data in a non-volatile memory (e.g. hard disk).
File I/O: Examples

in Python, a file operation takes place in the following order:

Open a file
Read or write (perform operation)
Close the file
Python has a built-in open() function to open a file. This function returns a file
object, also called a handle, as it is used to read or modify the file accordingly.
File I/O: Examples

 We can specify the mode while opening a file. In mode, we specify whether
we want to read r, write w or append a to the file. We can also specify if we
want to open the file in text mode or binary mode.
 The default is reading in text mode. In this mode, we get strings when
reading from the file.
Python Directory

 Python Directory
 If there are a large number of files to handle in our Python program, we can
arrange our code within different directories to make things more
manageable.
 We can get the present working directory using the getcwd() method of the os
module
 Changing Directory
 We can change the current working directory by using the chdir() method.
 Making a New Directory
 We can make a new directory using the mkdir() method.
Python Directory

 Renaming a Directory or a File


 The rename() method can rename a directory or a file.
 Removing Directory or File
 A file can be removed (deleted) using the remove() method
. 3.4 Handling IO Exceptions, Errors, Run
Time Errors.
 We can make certain mistakes while writing a program that lead to errors
when we try to run it. A python program terminates as soon as it encounters
an unhandled error. These errors can be broadly classified into two classes:

 Syntax errors
 Logical errors (Exceptions)
 Error caused by not following the proper structure (syntax) of the language is
called syntax error or parsing error.

 Let's look at one example:


. 3.4 Handling IO Exceptions, Errors, Run
Time Errors.
 >>> if a < 3
 File "<interactive input>", line 1
 if a < 3
 ^
 SyntaxError: invalid syntax
 As shown in the example, an arrow indicates where the parser ran into the
syntax error.

 We can notice here that a colon : is missing in the if statement.


3.4 Handling IO Exceptions, Errors, Run Time Errors.
.

 Errors that occur at runtime (after passing the syntax test) are called
exceptions or logical errors.

 For instance, they occur when we try to open a file(for reading) that does not
exist (FileNotFoundError), try to divide a number by zero (ZeroDivisionError),
or try to import a module that does not exist (ImportError).

 Whenever these types of runtime errors occur, Python creates an exception


object
An Introduction to relational databases

 We can connect to relational databases for analyzing data using the pandas
library as well as another additional library for implementing database
connectivity
 We will use Sqlite3 as our relational database as it is very light weight and
easy to use. Though the SQLAlchemy library can connect to a variety of
relational sources including MySql, Oracle and Postgresql and Mssql.
 The purpose of this post is to share the most commonly used SQL commands
for data manipulation and their counterparts in Python language
 .
SQL statements for data manipulation.

 Insert a single observation


 customer_table = customer_table.append(
 {'id': 1, 'age': 27, 'gender': 'Female'},
 ignore_index=True)
 In Python in order to display all rows and columns one can simply prompt the
name of the data frame
 customer_table
Using SQLite Manager to work with a
database
 When you open a CSV in python, and assign it to a variable name, you are using your
computers memory to save that variable. Accessing data from a database like SQL is
not only more efficient, but also it allows you to subset and import only the parts of the
data that you need.
 In the following lesson, we’ll see some approaches that can be taken to do so.
Using SQLite Manager to work with a
database
 import sqlite3

 # Create a SQL connection to our SQLite database


 con = sqlite3.connect("data/portal_mammals.sqlite")
cur = con.cursor()

 # The result of a "cursor.execute" can be iterated over by row


 for row in cur.execute('SELECT * FROM species;'):
 print(row)

 # Be sure to close the connection


 con.close()
Using Python to work with a database.

 Example
 create a database named "mydatabase":

 import mysql.connector

 mydb = mysql.connector.connect(
 host="localhost",
Using Python to work with a database.

 user="yourusername",
 password="yourpassword"
 )

 mycursor = mydb.cursor()

 mycursor.execute("CREATE DATABASE mydatabase")


Creating a GUI that handles an event
and working with components.
 How do you make an interactive GUI in Python?
 Tkinter Programming
 Tkinter is the standard GUI library for Python. Python when combined with
Tkinter provides a fast and easy way to create GUI applications. Tkinter
provides a powerful object-oriented interface to the Tk GUI toolkit.
 Import the Tkinter module.
 Create the GUI application main window.
 Add one or more of the above-mentioned widgets to the GUI application.
 Enter the main event loop to take action against each event triggered by the
user.
Usage of NumPy for numerical Data.

 NumPy is a general-purpose array-processing package. It provides a high-


performance multidimensional array object and tools for working with these
arrays. This article depicts how numeric data can be read from a file using
Numpy.
 Numerical data can be present in different formats of file :

 The data can be saved in a txt file where each line has a new data point.
 The data can be stored in a CSV(comma separated values) file.
 The data can be also stored in TSV(tab separated values) file.
Usage of Pandas for Data Analysis.

 Pandas provide tools for reading and writing data into data structures and
files. It also provides powerful aggregation functions to manipulate data.

 Pandas provide extended data structures to hold different types of labeled


and relational data. This makes python highly flexible and extremely useful
for data cleaning and manipulation.
 Pandas is highly flexible and provides functions for performing operations like
merging, reshaping, joining, and concatenating data.
Matplotlib for Python plotting.

 Define the x-axis and corresponding y-axis values as lists.


 Plot them on canvas using . plot() function.
 Give a name to x-axis and y-axis using . xlabel() and . ylabel() functions.
 Give a title to your plot using . title() function.
 Finally, to view your plot, we use . show() function.
5.4 Seaborn for Statistical plots.

 Seaborn is a popular data visualization library for Python


 Seaborn combines aesthetic appeal and technical insights – two crucial cogs in
a data science project
 Seaborn combines aesthetic appeal seamlessly with technical insights
 1. Textbooks:
 - Michael Urban and Joel Murach, Python Programming, Shroff/Murach, 2016
 - Halterman Python
 - Mark Lutz, Programming Python, O`Reilly, 4th Edition, 2010

 2. Reference Books:
 - To be added

 3. Web References:
 - https://www.w3schools.com/python
 - https://docs.python.org/3/tutorial/index.html
 - https://www.python-course.eu/advanced_topics.php
 - https://www.tutorialspoint.com/python3/
Seaborn for Statistical plots.

 Seaborn helps to visualize the statistical relationships, To understand how variables in a


dataset are related to one another and how that relationship is dependent on other
variables, we perform statistical analysis. This Statistical analysis helps to visualize the
trends and identify various patterns in the dataset.
 These are the plot will help to visualize:

 Line Plot
 Scatter Plot
 Box plot
 Point plot
 Count plot
 Violin plotataset.
 Machine Learning is about building programs with tunable parameters that
are adjusted automatically so as to improve their behavior by adapting to
previously seen data.
 Machine Learning can be considered a subfield of Artificial Intelligence since
those algorithms can be seen as building blocks to make computers learn to
behave more intelligently by somehow generalizing rather that just storing
and retrieving data items like a database system would do.
Thank you

You might also like