PYTHON LAB MANUAl
PYTHON LAB MANUAl
It is used for:
Why Python?
● 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.
Good to know
● The most recent major version of Python is Python 3, which we shall be
using in this tutorial. However, Python 2, although not being updated with
anything other than security updates, is still quite popular.
● In this tutorial Python will be written in a text editor. It is possible to write
Python in an Integrated Development Environment, such as Thonny, Pycharm,
Netbeans or Eclipse which are particularly useful when managing larger
collections of Python files.
Variables can store data of different types, and different types can do different
things.
Python has the following data types built-in by default, in these categories:
Output:
5 is of type <class 'int'>
2.0 is of type <class 'float'>
(1+2j) is of type <class 'complex'>
● 5 is an integer value, type() returns int as the class of num1 i.e <class 'int'>
● 2.0 is a floating value, type() returns float as the class of num2 i.e <class
'float'>
● 1 + 2j is a complex number, type() returns complex as the class
of num3 i.e <class 'complex'>
Python Operators
Operators are special symbols that perform operations on variables and values.
For example,
print(5 + 6) # 11
Run Code
1. Arithmetic Operators
2. Assignment Operators
3. Comparison Operators
4. Logical Operators
5. Bitwise Operators
6. Special Operators
sub = 10 - 5 # 5
Here, - is an arithmetic operator that subtracts two values or variables.
Operator Operation Example
+ Addition 5+2=7
- Subtraction 4-2=2
* Multiplication 2*3=6
/ Division 4/2=2
// Floor Division 10 // 3 = 3
% Modulo 5%2=1
** Power 4 ** 2 = 16
a=7
b=2
# addition
print ('Sum: ', a + b)
# subtraction
print ('Subtraction: ', a - b)
# multiplication
print ('Multiplication: ', a * b)
# division
print ('Division: ', a / b)
# floor division
print ('Floor Division: ', a // b)
# modulo
print ('Modulo: ', a % b)
# a to the power b
print ('Power: ', a ** b)
Output
Sum: 9
Subtraction: 5
Multiplication: 14
Division: 3.5
Floor Division: 3
Modulo: 1
Power: 49
In the above example, we have used multiple arithmetic operators,
● + to add a and b
● - to subtract b from a
● * to multiply a and b
● / to divide a by b
● // to floor divide a by b
● % to get the remainder
● ** to get a to the power b
# assign 5 to x
x=5
Here, = is an assignment operator that assigns 5 to x.
Here's a list of different assignment operators available in Python.
# assign 5 to b
b=5
print(a)
Output: 15
a=5
b=2
# equal to operator
print('a == b =', a == b)
Output
a == b = False
a != b = True
a > b = True
a < b = False
a >= b = True
a <= b = False
Here, and is the logical operator AND. Since both a > 2 and b >= 6 are True, the
result is True.
Operator Example Meaning
Logical AND:
and a and b True only if both the operands are True
Logical OR:
or a or b True if at least one of the operands is True
Logical NOT:
not not a True if the operand is False and vice-versa.
# logical NOT
print(not True) # False
Output:
False
True
False
● Equals: a == b
● Not Equals: a != b
● Less than: a < b
● Less than or equal to: a <= b
● Greater than: a > b
● Greater than or equal to: a >= b
7. Write a program to demonstrate conditions and if
statements in python
If statement:
a = 33
b = 200
if b > a:
print("b is greater than a")
Output:
b is greater than a
Elif
The elif keyword is Python's way of saying "if the previous conditions were not true,
then try this condition".
a = 33
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
Output:
a and b are equal
Else
The else keyword catches anything which isn't caught by the preceding conditions.
a = 200
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
else:
print("a is greater than b")
Output:
a is greater than b
And
The and keyword is a logical operator, and is used to combine conditional
statements:
Example
Test if a is greater than b, AND if c is greater than a:
a = 200
b = 33
c = 500
if a > b and c > a:
print("Both conditions are True")
Output:
Both conditions are True
Or
The or keyword is a logical operator, and is used to combine conditional statements:
Example
Test if a is greater than b, OR if a is greater than c:
a = 200
b = 33
c = 500
if a > b or a > c:
print("At least one of the conditions is True")
Output:
At least one of the conditions is True
Nested If
You can have if statements inside if statements, this is called nested if statements.
Example
x = 41
if x > 10:
print("Above ten,")
if x > 20:
print("and also above 20!")
else:
print("but not above 20.")
Output:
Above ten,
and also above 20!
An iterator is an object that can be iterated upon, meaning that you can traverse
through all the values.
Lists, tuples, dictionaries, and sets are all iterable objects. They are
iterable containers which you can get an iterator from.
All these objects have a iter() method which is used to get an iterator:
print(next(myit))
print(next(myit))
print(next(myit))
Output:
apple
banana
cherry
Even strings are iterable objects, and can return an iterator:
mystr = "banana"
myit = iter(mystr)
print(next(myit))
print(next(myit))
print(next(myit))
print(next(myit))
print(next(myit))
print(next(myit))
Output:
b
a
n
a
n
a
Example
Iterate the values of a tuple:
for x in mytuple:
print(x)
Output:
apple
banana
cherry
Create an Iterator
To create an object/class as an iterator you have to implement the
methods __iter__() and __next__() to your object.
As you have learned in the Python Classes/Objects chapter, all classes have a
function called __init__(), which allows you to do some initializing when the object is
being created.
The __iter__() method acts similar, you can do operations (initializing etc.), but must
always return the iterator object itself.
The __next__() method also allows you to do operations, and must return the next
item in the sequence.
Example
Create an iterator that returns numbers, starting with 1, and each sequence will
increase by one (returning 1,2,3,4,5 etc.):
class MyNumbers:
def __iter__(self):
self.a = 1
return self
def __next__(self):
x = self.a
self.a += 1
return x
myclass = MyNumbers()
myiter = iter(myclass)
print(next(myiter))
print(next(myiter))
print(next(myiter))
print(next(myiter))
print(next(myiter))
Output:
1
2
3
4
5
Create a Module
To create a module just save the code you want in a file with the file extension .py:
Example
Save this code in a file named mymodule.py
def greeting(name):
print("Hello, " + name)
Use a Module
Now we can use the module we just created, by using the import statement:
Example
Import the module named mymodule, and call the greeting function:
import mymodule
mymodule.greeting("SSIT")
Output:
Hello, SSIT
Variables in Module
The module can contain functions, as already described, but also variables of all
types (arrays, dictionaries, objects etc):
Example
Save this code in the file mymodule.py
person1 = {
"name": "John",
"age": 36,
"country": "Norway"
}
Import the module named mymodule, and access the person1 dictionary:
import mymodule
a = mymodule.person1["age"]
print(a)
Re-naming a Module
You can create an alias when you import a module, by using the as keyword:
Example
Create an alias for mymodule called mx:
import mymodule as mx
a = mx.person1["age"]
print(a)
Output:
36
Built-in Modules
There are several built-in modules in Python, which you can import whenever you like.
Example
Import and use the platform module:
import platform
x = platform.system()
print(x)
Output:
Windows
Example
The module named mymodule has one function and one dictionary:
def greeting(name):
print("Hello, " + name)
person1 = {
"name": "John",
"age": 36,
"country": "Norway"
}
Example
Import only the person1 dictionary from the module:
print (person1["age"])
Output:
36
Example
print("Hello")
print('Hello')
Output:
Hello
Hello
Assign String to a Variable
Assigning a string to a variable is done with the variable name followed by an equal
sign and the string:
Example
a = "Hello"
print(a)
Output:
Hello
Strings are Arrays
Like many other popular programming languages, strings in Python are arrays of
bytes representing unicode characters.
However, Python does not have a character data type, a single character is simply a
string with a length of 1.
Example
Get the character at position 1 (remember that the first character has the position 0):
a = "Hello, World!"
print(a[1])
Output:
e
String Length
Example
The len() function returns the length of a string:
a = "Hello, World!"
print(len(a))
Output:
13
11.Write a program to demonstrate Tuples in python.
Python Tuples
mytuple = ("apple", "banana", "cherry")
Tuple
Tuple is one of 4 built-in data types in Python used to store collections of data, the
other 3 are List, Set, and Dictionary, all with different qualities and usage.
Example
Create a Tuple:
Output:
('apple', 'banana', 'cherry')
To create a tuple with only one item, you have to add a comma after the item,
otherwise Python will not recognize it as a tuple.
Example
One item tuple, remember the comma:
thistuple = ("apple",)
print(type(thistuple))
#NOT a tuple
thistuple = ("apple")
print(type(thistuple))
Output:
<class 'tuple'>
<class 'str'>
Example
String, int and boolean data types:
Output:
('apple', 'banana', 'cherry')
(1, 5, 7, 9, 3)
(True, False, False)
Python Lists
Lists are used to store multiple items in a single variable.
Lists are one of 4 built-in data types in Python used to store collections of data, the
other 3 are Tuple, Set, and Dictionary, all with different qualities and usage.
Dictionary
Dictionaries are used to store data values in key:value pairs.
As of Python version 3.7, dictionaries are ordered. In Python 3.6 and earlier,
dictionaries are unordered.
Dictionaries are written with curly brackets, and have keys and values:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(thisdict)
Output:
{'brand': 'Ford', 'model': 'Mustang', 'year': 1964}
Dictionary Items
Dictionary items are ordered, changeable, and do not allow duplicates.
Dictionary items are presented in key:value pairs, and can be referred to by using the
key name.
Output:
Ford
Set is one of 4 built-in data types in Python used to store collections of data, the
other 3 are List, Tuple, and Dictionary, all with different qualities and usage.
* Note: Set items are unchangeable, but you can remove items and add new items.
Create a Set:
Python has several functions for creating, reading, updating, and deleting files.
File Handling
The key function for working with files in Python is the open() function.
"a" - Append - Opens a file for appending, creates the file if it does not exist
"w" - Write - Opens a file for writing, creates the file if it does not exist
"x" - Create - Creates the specified file, returns an error if the file exists
In addition you can specify if the file should be handled as binary or text mode
Syntax
To open a file for reading it is enough to specify the name of the file:
f = open("demofile.txt")
f = open("demofile.txt", "rt")
Because "r" for read, and "t" for text are the default values, you do not need to specify
them.
demofile.txt
The open() function returns a file object, which has a read() method for reading the
content of the file:
Example
f = open("demofile.txt", "r")
print(f.read())
Output:
Hello! Welcome to demofile.txt
This file is for testing purposes.
Good Luck!
If the file is located in a different location, you will have to specify the file path, like
this:
Example
Open a file on a different location:
f = open("D:\\myfiles\welcome.txt", "r")
print(f.read())
Output:
Welcome to this text file!
This file is located in a folder named "myfiles", on the D drive.
Good Luck!
Example
Open the file "demofile2.txt" and append content to the file:
f = open("demofile2.txt", "a")
f.write("Now the file has more content!")
f.close()
f = open("demofile3.txt", "w")
f.write("Woops! I have deleted the content!")
f.close()
"x" - Create - will create a file, returns an error if the file exist
"a" - Append - will create a file if the specified file does not exist
"w" - Write - will create a file if the specified file does not exist
Example
Create a file called "myfile.txt":
f = open("myfile.txt", "x")
Example
Create a new file if it does not exist:
f = open("myfile.txt", "w")
import os
os.remove("demofile.txt")
Example
Check if file exists, then delete it:
import os
if os.path.exists("demofile.txt"):
os.remove("demofile.txt")
else:
print("The file does not exist")
Delete Folder
To delete an entire folder, use the os.rmdir() method:
Example
Remove the folder "myfolder":
import os
os.rmdir("myfolder")
The finally block lets you execute code, regardless of the result of the try- and except
blocks.
Exception Handling
When an error occurs, or exception as we call it, Python will normally stop and
generate an error message.
Example
The try block will generate an exception, because x is not defined:
try:
print(x)
except:
print("An exception occurred")
Output:
An exception occurred
Since the try block raises an error, the except block will be executed.
Without the try block, the program will crash and raise an error:
Example
This statement will raise an error, because x is not defined:
print(x)
NumPy Tutorial
NumPy is a Python library.
Example
Create a NumPy array:
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(arr)
print(type(arr))
Example
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(arr)
print(type(arr))
Output:
[1 2 3 4 5]
<class 'numpy.ndarray'>
To create an ndarray, we can pass a list, tuple or any array-like object into
the array() method, and it will be converted into an ndarray:
Example
Use a tuple to create a NumPy array:
import numpy as np
arr = np.array((1, 2, 3, 4, 5))
print(arr)
Output:
[1 2 3 4 5]
Dimensions in Arrays
A dimension in arrays is one level of array depth (nested arrays).
0-D Arrays
0-D arrays, or Scalars, are the elements in an array. Each value in an array is a 0-D
array.
Example
Create a 0-D array with value 42
import numpy as np
arr = np.array(42)
print(arr)
Output:
42
1-D Arrays
An array that has 0-D arrays as its elements is called uni-dimensional or 1-D array.
Example
Create a 1-D array containing the values 1,2,3,4,5:
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(arr)
Output:
[1 2 3 4 5]
2-D Arrays
An array that has 1-D arrays as its elements is called a 2-D array.
Example
Create a 2-D array containing two arrays with the values 1,2,3 and 4,5,6:
import numpy as np
arr = np.array([[1, 2, 3], [4, 5, 6]])
print(arr)
Output:
[[1 2 3]
[4 5 6]]
3-D arrays
An array that has 2-D arrays (matrices) as its elements is called 3-D array.
Example
Create a 3-D array with two 2-D arrays, both containing two arrays with the values
1,2,3 and 4,5,6:
import numpy as np
print(arr)
The indexes in NumPy arrays start with 0, meaning that the first element has index 0,
and the second has index 1 etc.
import numpy as np
print(arr[0])
Output:
1
Example
Get the second element from the following array.
import numpy as np
print(arr[1])
Output:
2
Example
Get third and fourth elements from the following array and add them.
import numpy as np
print(arr[2] + arr[3])
Output:
7
Think of 2-D arrays like a table with rows and columns, where the dimension
represents the row and the index represents the column.
Example
Access the element on the first row, second column:
import numpy as np
Output:
2nd element on 1st dim: 2
Example
Access the element on the 2nd row, 5th column:
import numpy as np
Example
Access the third element of the second array of the first array:
import numpy as np
arr = np.array([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]])
print(arr[0, 1, 2])
Output:
6
Example Explained
arr[0, 1, 2] prints the value 6.
The first number represents the first dimension, which contains two arrays:
[[1, 2, 3], [4, 5, 6]]
and:
[[7, 8, 9], [10, 11, 12]]
Since we selected 0, we are left with the first array:
[[1, 2, 3], [4, 5, 6]]
The second number represents the second dimension, which also contains two
arrays:
[1, 2, 3]
and:
[4, 5, 6]
Since we selected 1, we are left with the second array:
[4, 5, 6]
The third number represents the third dimension, which contains three values:
4
5
6
Since we selected 2, we end up with the third value:
6
import numpy as np
newarr = arr.reshape(4, 3)
print(newarr)
Output:
[[ 1 2 3]
[ 4 5 6]
[ 7 8 9]
[10 11 12]]
The outermost dimension will have 2 arrays that contains 3 arrays, each with 2
elements:
import numpy as np
newarr = arr.reshape(2, 3, 2)
print(newarr)
Output:
[[[ 1 2]
[ 3 4]
[ 5 6]]
[[ 7 8]
[ 9 10]
[11 12]]]
Python Math
18.Write a program to demonstrate Math in python.
Python has a set of built-in math functions, including an extensive math module,
that allows you to perform mathematical tasks on numbers.
Example
x = min(5, 10, 25)
y = max(5, 10, 25)
print(x)
print(y)
Output:
5
25
The abs() function returns the absolute (positive) value of the specified number:
Example
x = abs(-7.25)
print(x)
Output:
7.25
y
The pow(x, y) function returns the value of x to the power of y (x ).
Example
Return the value of 4 to the power of 3 (same as 4 * 4 * 4):
x = pow(4, 3)
print(x)
Output:
64
import math
When you have imported the math module, you can start using methods and
constants of the module.
The math.sqrt() method for example, returns the square root of a number:
Example
import math
x = math.sqrt(64)
print(x)
Output:
8.0
The math.ceil() method rounds a number upwards to its nearest integer, and
the math.floor() method rounds a number downwards to its nearest integer, and
returns the result:
Example
import math
x = math.ceil(1.4)
y = math.floor(1.4)
print(x) # returns 2
print(y) # returns 1
Output:
2
1
Example
import math
x = math.pi
print(x)
import pandas as pd
Output:
Series:
0 10
1 20
2 30
3 40
4 50
dtype: int64
Explanation of Code:
1. Creating a Series:
o You can also create a Series with custom indices, such as ['a', 'b', 'c', 'd',
'e'].
2. Accessing Data:
3. Arithmetic Operations:
4. Basic Statistics:
o You can use methods like .mean() and .sum() to calculate basic
statistics like the mean or sum of the Series.
5. Conditional Statements:
o You can check conditions on the Series to return a boolean result (like
whether elements are greater than 25).
import pandas as pd
data = {
df = pd.DataFrame(data)
print("DataFrame:")
print(df)
print(df['Age'])
# Access specific row by index
print(df.iloc[0])
print(df.iloc[:3])
print(df.at[1, 'City'])
print(df)
print(df)
# Filter rows based on a condition (Age > 25)
print(df.describe())
# Drop a column
df = df.drop('City', axis=1)
print(df)
# Rename columns
print(df)
Output:
DataFrame:
Name Age City
0 Alice 24 New York
1 Bob 27 Los Angeles
2 Charlie 22 Chicago
3 David 32 Houston
4 Eve 29 Phoenix
Access 'Age' column:
0 24
1 27
2 22
3 32
4 29
Name: Age, dtype: int64
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.DataFrame(data)
Output Examples:
1. Line Plot (Salary vs Experience): A line graph showing how salary
increases with experience.
2. Scatter Plot (Age vs Salary): A scatter plot showing how age correlates
with salary.
3. Histogram (Salary Distribution): A histogram with a KDE curve showing
the distribution of salaries.
4. Box Plot (Salary by City): A box plot showing salary distribution for
different cities.
5. Correlation Heatmap: A heatmap showing how strongly the variables
Age, Salary, and Experience are correlated.
6. Pairplot: A grid of scatter plots that shows relationships between
multiple pairs of columns.
# Sample data
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
sales = [2300, 2500, 2700, 3000, 3500, 4000, 4500, 4800, 5000, 5500, 6000,
6500]
Output:
This code will generate a line chart showing the monthly sales from January to
December. The chart will have the following features:
● The months will be plotted on the x-axis.
● The sales figures will be plotted on the y-axis.
● A solid blue line connects the data points for each month, with circular
markers at each point.
● A title and axis labels will be displayed to clarify what the chart
represents.
Copy code
# Sample data
plt.figure(figsize=(8, 5))
plt.xlabel('Category', fontsize=12)
plt.ylabel('Value', fontsize=12)
Explanation:
1. Data Preparation:
o categories: A list of category names.
o values: A list of values corresponding to each category.
2. Bar Chart Creation:
o plt.bar(categories, values, color='skyblue'): This creates the bar
chart with categories on the x-axis and values on the y-axis. The
color of the bars is set to sky blue.
3. Titles and Labels:
o The title and axis labels are added using plt.title(), plt.xlabel(), and
plt.ylabel().
4. Displaying the Chart:
o plt.show(): This displays the bar chart.
Output:
This will generate a simple bar chart with categories on the x-axis and
corresponding values on the y-axis.
Copy code
# Sample data
data = {
import pandas as pd
df = pd.DataFrame(data)
plt.figure(figsize=(8, 5))
plt.xlabel('Category', fontsize=12)
plt.ylabel('Value', fontsize=12)
plt.show()
Explanation:
1. Data Preparation:
o We create a Pandas DataFrame df from a dictionary. The dictionary
contains Category names and their corresponding Value.
2. Bar Chart Creation with Seaborn:
o sns.barplot(x='Category', y='Value', data=df, palette='viridis'): This
creates the bar chart using the barplot() function, where
x='Category' and y='Value' refer to the columns of the DataFrame.
The palette parameter is used to define the color palette for the
bars.
3. Titles and Labels:
o Just like with Matplotlib, we add the title and axis labels using
plt.title(), plt.xlabel(), and plt.ylabel().
4. Displaying the Chart:
o plt.show() is used to display the Seaborn-generated bar chart.
Output:
This will generate a bar chart similar to the one created with Matplotlib,
but with Seaborn’s built-in color palette and additional styling options.
Copy code
plt.figure(figsize=(8, 8))
# Add a title
plt.show()
Explanation:
1. Data Preparation:
o categories: A list of categories or labels.
o values: A list of corresponding values for each category.
2. Creating the Pie Chart:
o plt.pie(values, labels=categories, autopct='%1.1f%%',
startangle=140): This function creates the pie chart.
● values: The data for each category (the size of each slice).
● labels: The labels for each slice.
● autopct='%1.1f%%': This formats the percentage of each slice with
one decimal point.
● startangle=140: This rotates the start angle of the pie chart to 140
degrees for better readability.
● colors: Specifies the color for each slice.
3. Title:
o The title of the chart is set using plt.title().
4. Displaying the Chart:
o plt.show() is used to display the pie chart.
Output:
This will generate a pie chart that shows the distribution of values
across the categories, with each slice labeled by its percentage.
Copy code
sns.set(style="whitegrid")
plt.figure(figsize=(8, 8))
# Add a title
plt.show()
Explanation:
1. Seaborn Styling:
o sns.set(style="whitegrid"): This applies Seaborn's whitegrid style,
which adds a light grid to the background and improves the overall
appearance.
2. Color Palette:
o colors=sns.color_palette("Set2", len(values)): This uses Seaborn's
built-in color palette Set2, which provides a set of attractive,
distinct colors for the pie chart slices.
3. Rest of the Chart Creation:
o The rest of the chart creation process is identical to the previous
Matplotlib example.
Output:
This will generate a pie chart similar to the previous one, but with
Seaborn's color palette and grid style, making the chart look more
polished.
Copy code
# Sample data
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
plt.figure(figsize=(8, 5))
plt.xlabel('x', fontsize=12)
plt.ylabel('y', fontsize=12)
plt.grid(True)
plt.show()
Explanation:
1. Data Preparation:
o x and y represent the x-axis and y-axis data points.
o In this example, the relationship between x and y is quadratic (i.e.,
y=x2y = x^2y=x2).
2. Scatter Plot Creation:
o plt.scatter(x, y): This creates the scatter plot where x and y are the
data points.
o color='blue': The color of the scatter points.
o marker='o': The shape of the points (circles in this case).
o s=100: The size of each scatter point (100 pixels).
o edgecolors='black': The color of the edges around each point.
3. Adding Titles and Labels:
o plt.title(), plt.xlabel(), and plt.ylabel() are used to add the title and
axis labels.
4. Displaying the Plot:
o plt.show() displays the plot.
o plt.grid(True) adds a grid to the plot for better readability.
Output:
This will display a scatter plot of the data points with a quadratic
relationship between x and y.
Copy code
# Sample data
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
import pandas as pd
plt.figure(figsize=(8, 5))
plt.xlabel('x', fontsize=12)
plt.ylabel('y', fontsize=12)
plt.show()
Explanation:
1. Data Preparation:
o A Pandas DataFrame df is created to hold the data, which is
required by Seaborn for plotting.
2. Scatter Plot Creation:
o sns.scatterplot(data=df, x='x', y='y'): This creates the scatter plot
using Seaborn's scatterplot() function. The data argument is the
DataFrame, and x and y specify the columns to plot.
o color='green': The color of the scatter points.
o marker='o': The shape of the points (circles).
o s=100: The size of each scatter point.
3. Adding Titles and Labels:
o Just like with Matplotlib, plt.title(), plt.xlabel(), and plt.ylabel() are
used to set the title and labels.
4. Displaying the Plot:
o plt.show() is used to display the plot.
Output: