0% found this document useful (0 votes)
11 views

SBLC 1

The document discusses how to create and manipulate data frames using the Pandas library in Python. It covers creating data frames from various data types like lists, dictionaries, and Series. It also covers selecting, adding, and deleting both columns and rows from a data frame.

Uploaded by

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

SBLC 1

The document discusses how to create and manipulate data frames using the Pandas library in Python. It covers creating data frames from various data types like lists, dictionaries, and Series. It also covers selecting, adding, and deleting both columns and rows from a data frame.

Uploaded by

Raj
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

EXPERIMENT NO: 9

Date of Performance :

Date of Submission :
AIM: Program to demonstrate Data Frames using Pandas
THEORY:
A Data frame is a two-dimensional data structure, i.e., data is aligned in a tabular fashion in rows and
columns.
Features of DataFrame
● Potentially columns are of different types
● Size – Mutable
● Labeled axes (rows and columns)
● Can Perform Arithmetic operations on rows and columns
Structure
Let us assume that we are creating a data frame with student‟s data.

You can think of it as an SQL table or a spreadsheet data representation.


pandas.DataFrame
A pandas DataFrame can be created using the following constructor −
pandas.DataFrame( data, index, columns, dtype, copy)
The parameters of the constructor are as follows −
Sr.No Parameter & Description
data
1 data takes various forms like ndarray, series, map, lists, dict, constants and also another
DataFrame.
index
2 For the row labels, the Index to be used for the resulting frame is Optional Default np.arange(n) if
no index is passed.
columns
3 For column labels, the optional default syntax is - np.arange(n). This is only true if no index is
passed.
dtype
4
Data type of each column.
copy
5
This command (or whatever it is) is used for copying of data, if the default is False.
Create DataFrame
A pandas DataFrame can be created using various inputs like −
● Lists
● dict
● Series
● Numpy ndarrays
● Another DataFrame
In the subsequent sections of this chapter, we will see how to create a DataFrame using these inputs.
Create an Empty DataFrame
A basic DataFrame, which can be created is an Empty Dataframe.
Example

#import the pandas library and aliasing as pd


import pandas as pd
df = pd.DataFrame()
print df
Its output is as follows −
Empty DataFrame
Columns: []
Index: []
Create a DataFrame from Lists
The DataFrame can be created using a single list or a list of lists.
Example 1
import pandas as pd
data =[1,2,3,4,5]
df = pd.DataFrame(data)
print df
Its output is as follows −
0
0 1
1 2
2 3
3 4
4 5
Example 2

import pandas as pd
data =[['Alex',10],['Bob',12],['Clarke',13]]
df = pd.DataFrame(data,columns=['Name','Age'])
print df
Its output is as follows −
Name Age
0 Alex 10
1 Bob 12
2 Clarke 13
Example 3

import pandas as pd
data =[['Alex',10],['Bob',12],['Clarke',13]]
df = pd.DataFrame(data,columns=['Name','Age'],dtype=float)
print df
Its output is as follows −
Name Age
0 Alex 10.0
1 Bob 12.0
2 Clarke 13.0
Note − Observe, the dtype parameter changes the type of Age column to floating point.
Create a DataFrame from Dict of ndarrays / Lists
All the ndarrays must be of same length. If index is passed, then the length of the index should equal to
the length of the arrays.
If no index is passed, then by default, index will be range(n), where n is the array length.
Example 1

import pandas as pd
data ={'Name':['Tom','Jack','Steve','Ricky'],'Age':[28,34,29,42]}
df = pd.DataFrame(data)
print df
Its output is as follows −
Age Name
0 28 Tom
1 34 Jack
2 29 Steve
3 42 Ricky
Note − Observe the values 0,1,2,3. They are the default index assigned to each using the function
range(n).
Example 2
Let us now create an indexed DataFrame using arrays.

import pandas as pd
data ={'Name':['Tom','Jack','Steve','Ricky'],'Age':[28,34,29,42]}
df = pd.DataFrame(data, index=['rank1','rank2','rank3','rank4'])
print df
Its output is as follows −
Age Name
rank1 28 Tom
rank2 34 Jack
rank3 29 Steve
rank4 42 Ricky
Note − Observe, the index parameter assigns an index to each row.
Create a DataFrame from List of Dicts
List of Dictionaries can be passed as input data to create a DataFrame. The dictionary keys are by
default taken as column names.
Example 1
The following example shows how to create a DataFrame by passing a list of dictionaries.

import pandas as pd
data =[{'a':1,'b':2},{'a':5,'b':10,'c':20}]
df = pd.DataFrame(data)
print df
Its output is as follows −
a b c
0 1 2 NaN
1 5 10 20.0
Note − Observe, NaN (Not a Number) is appended in missing areas.
Example 2
The following example shows how to create a DataFrame by passing a list of dictionaries and the row
indices.

import pandas as pd
data =[{'a':1,'b':2},{'a':5,'b':10,'c':20}]
df = pd.DataFrame(data, index=['first','second'])
print df
Its output is as follows −
a b c
first 1 2 NaN
second 5 10 20.0
Example 3
The following example shows how to create a DataFrame with a list of dictionaries, row indices, and
column indices.

import pandas as pd
data =[{'a':1,'b':2},{'a':5,'b':10,'c':20}]

#With two column indices, values same as dictionary keys


df1 = pd.DataFrame(data, index=['first','second'], columns=['a','b'])

#With two column indices with one index with other name
df2 = pd.DataFrame(data, index=['first','second'], columns=['a','b1'])
print df1
print df2
Its output is as follows −
#df1 output
a b
first 1 2
second 5 10

#df2
output b1
a
first 1 NaN
second 5 NaN
Note − Observe, df2 DataFrame is created with a column index other than the dictionary key; thus,
appended the NaN‟s in place. Whereas, df1 is created with column indices same as dictionary keys, so
NaN‟s appended.
Create a DataFrame from Dict of Series
Dictionary of Series can be passed to form a DataFrame. The resultant index is the union of all the series
indexes passed.
Example

import pandas as pd

d ={'one': pd.Series([1,2,3], index=['a','b','c']),


'two': pd.Series([1,2,3,4], index=['a','b','c','d'])}

df = pd.DataFrame(d)
print df
Its output is as follows −
one two
a 1.0 1
b 2.0 2
c 3.0 3
d NaN 4
Note − Observe, for the series one, there is no label ‘d’ passed, but in the result, for the d label, NaN is appended
with NaN.
Let us now understand column selection, addition, and deletion through examples.
Column Selection
We will understand this by selecting a column from the DataFrame.
Example

import pandas as pd

d ={'one': pd.Series([1,2,3], index=['a','b','c']),


'two': pd.Series([1,2,3,4], index=['a','b','c','d'])}

df = pd.DataFrame(d)
print df ['one']
Its output is as follows −
a 1.0
b 2.0
c 3.0
d NaN
Name: one, dtype: float64
Column Addition
We will understand this by adding a new column to an existing data frame.
Example

import pandas as pd

d ={'one': pd.Series([1,2,3], index=['a','b','c']),


'two': pd.Series([1,2,3,4], index=['a','b','c','d'])}

df = pd.DataFrame(d)
# Adding a new column to an existing DataFrame object with column label by passing
new series

print("Adding a new column by passing as Series:")


df['three']=pd.Series([10,20,30],index=['a','b','c'
]) print df

print("Adding a new column using the existing columns in DataFrame:")


df['four']=df['one']+df['three']

print df
Its output is as follows −
Adding a new column by passing as Series:
one two three
a 1.0 1 10.0
b 2.0 2 20.0
c 3.0 3 30.0
d NaN 4 NaN

Adding a new column using the existing columns in DataFrame:


one two three four
a 1.0 1 10.0 11.0
b 2.0 2 20.0 22.0
c 3.0 3 30.0 33.0
d NaN 4 NaN NaN
Column Deletion
Columns can be deleted or popped; let us take an example to understand how.
Example

# Using the previous DataFrame, we will delete a column


# using del function
import pandas as pd

d ={'one': pd.Series([1,2,3], index=['a','b','c']),


'two': pd.Series([1,2,3,4], index=['a','b','c','d']),
'three': pd.Series([10,20,30], index=['a','b','c'])}

df = pd.DataFrame(d)
print("Our dataframe is:")
print df

# using del function


print("Deleting the first column using DEL function:")
del df['one']
print df

# using pop function


print("Deleting another column using POP function:")
df.pop('two')
print df
Its output is as follows −
Our dataframe is:
one three two
a 1.0 10.0 1
b 2.0 20.0 2
c 3.0 30.0 3
d NaN NaN 4

Deleting the first column using DEL function:


three two
a 10.0 1
b 20.0 2
c 30.0 3
d NaN 4

Deleting another column using POP function:


three
a 10.0
b 20.0
c 30.0
d NaN
Row Selection, Addition, and Deletion
We will now understand row selection, addition and deletion through examples. Let us begin with the
concept of selection.
Selection by Label
Rows can be selected by passing row label to a loc function.

import pandas as pd

d ={'one': pd.Series([1,2,3], index=['a','b','c']),


'two': pd.Series([1,2,3,4], index=['a','b','c','d'])}

df = pd.DataFrame(d)
print df.loc['b']
Its output is as follows −
one 2.0
two 2.0
Name: b, dtype: float64
The result is a series with labels as column names of the DataFrame. And, the Name of the series is the
label with which it is retrieved.
Selection by integer location
Rows can be selected by passing integer location to an iloc function.

import pandas as pd

d ={'one': pd.Series([1,2,3], index=['a','b','c']),


'two': pd.Series([1,2,3,4], index=['a','b','c','d'])}

df = pd.DataFrame(d)
print df.iloc[2]
Its output is as follows −
one 3.0
two 3.0
Name: c, dtype: float64
Slice Rows
Multiple rows can be selected using „ : ‟ operator.
import pandas as pd
d ={'one': pd.Series([1,2,3], index=['a','b','c']),
'two': pd.Series([1,2,3,4], index=['a','b','c','d'])}

df = pd.DataFrame(d)
print df[2:4]
Its output is as follows −
one two
c 3.0 3
d NaN 4
Addition of Rows
Add new rows to a DataFrame using the append function. This function will append the rows at the end.

import pandas as pd

df = pd.DataFrame([[1,2],[3,4]], columns =['a','b'])


df2 = pd.DataFrame([[5,6],[7,8]], columns =['a','b'])

df = df.append(df2)
print df
Its output is as follows −
a b
0 1 2
1 3 4
0 5 6
1 7 8
Deletion of Rows
Use index label to delete or drop rows from a DataFrame. If label is duplicated, then multiple rows will
be dropped.
If you observe, in the above example, the labels are duplicate. Let us drop a label and will see how many
rows will get dropped.

import pandas as pd
df = pd.DataFrame([[1,2],[3,4]], columns =['a','b'])
df2 = pd.DataFrame([[5,6],[7,8]], columns =['a','b'])

df = df.append(df2)

# Drop rows with label 0


df = df.drop(0)

print df
Its output is as follows −
a b
1 3 4
1 7 8
CODE
import pandas as pd

# Create a DataFrame
data = {'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Eve'],
'Age': [25, 30, 35, 40, 45],
'City': ['New York', 'Los Angeles', 'Chicago', 'Houston', 'Phoenix']}
df = pd.DataFrame(data)

# Display the DataFrame


print("DataFrame:")
print(df)

# Display the first two rows


print("\nFirst two rows:")
print(df.head(2))

# Describe the DataFrame


print("\nDescribe Method:")
print(df.describe())

CONCLUSION: Program executed successfully


R1 R2 R3 R4 Total Signature
(3 Marks) (3 Marks) (3 Marks) (1 Mark) (10 Marks)
EXPERIMENT NO: 10
Date of Performance :

Date of Submission :

AIM: Menu driven program for data structure using built in function for link list, stack
and queues.

THEORY:
A list is a data structure in Python that is a mutable, or changeable, ordered sequence of elements.
Each element or value that is inside of a list is called an item. Just as strings are defined as
characters between quotes, lists are defined by having values between square brackets [ ]. Lists
are great to use when you want to work with many related values. They enable you to keep data
together that belongs together, condense your code, and perform the same methods and operations
on multiple values atonce.
The list data type has some more methods. Here are all of the
methods of list objects: list.append(x)
Add an item to the end of the list; equivalent to
a[len(a):] = [x]. list.extend(L)
Extend the list by appending all the items in the given list; equivalent to a[len(a):] = L.
list.insert(i, x)
Insert an item at a given position. The first argument is the index of the element before
which to insert, so a.insert(0, x) inserts at the front of the list, and a.insert(len(a), x) is
equivalent toa.append(x).
list.remove(x)
Remove the first item from the list whose value is x. It is an error if there
is no such item. list.pop([i])
Remove the item at the given position in the list, and return it. If no index is specified, a.pop() removes
and
returns the last item in the list. (The square brackets around the i in the method signature denote
that the parameter is optional, not that you should type square brackets at that position. You will
see this notation frequently in the Python Library Reference.)
list.index(x)
Return the index in the list of the first item whose value is x. It is an error if there
is no such item. list.count(x)
Return the number of times x appears in the list.
list.sort()

Sort the items of


the list, in place.
list.reverse()
Reverse the elements of the list, in place.

Using List as Stack

The list methods make it very easy to use a list as a stack, where the last element added is the first
element retrieved (“last-in, first-out”). To add an item to the top of the stack, use append(). To
retrieve an item from the top of the stack, use pop() without an explicit index.

Using List as Queues

It is also possible to use a list as a queue, where the first element added is the first element retrieved
(“first-in, first-out”); however, lists are not efficient for this purpose. While appends and pops from
the end of list are fast, doing inserts or pops from the beginning of a list is slow (because all of the
other elements have to be shifted by one).

To implement a queue, use collections.deque which was designed to have fast appends and pops
from both ends.
ENQUEUE
# Stack Implementation
def isEmpty(stk):
return len(stk) == 0

def Push(stk, item):


stk.append(item)
top = len(stk) - 1

def Pop(stk):
if isEmpty(stk):
print("Underflow")
else:
item = stk.pop()
if len(stk) == 0:
top = None
else:
top = len(stk)
print("Popped item is " + str(item))
def Display(stk):
if isEmpty(stk):
print("Stack is empty")
else:
top = len(stk) - 1
print("Elements in the stack are:")
for i in range(top, -1, -1):
print(str(stk[i]))

if __name__ == "__main__":
stk = []
top = None

Push(stk, 1)
Push(stk, 2)
Push(stk, 3)
Push(stk, 4)
Pop(stk)
Display(stk)

# Queue Implementation
def enque(queue, data):
queue.insert(0, data)

def dequeue(queue):
if len(queue) > 0:
return queue.pop()
return "Queue Empty"

def display(queue):
print("Elements in the queue are:")
for i in range(len(queue)):
print(queue[i])

if __name__ == "__main__":
queue = []
enque(queue, 5)
enque(queue, 6)
enque(queue, 9)
enque(queue, 5)
enque(queue, 3)
print("Popped Element is: " + str(dequeue(queue)))
display(queue)
DEQUEUE

import collections

d = collections.deque('abcdefg')
print('Deque:', d )
print ('Length:', len(d))
print ('Left end:', d[0] )
print ('Right end:', d[-1] )
d.popleft()
print("Deque after popleft:",d)
d.pop()
print("Deque after pop :",d)
d.extendleft([0])
d.extend([6,7,8])
print(d)

CONCLUSION: Program executed successfully

R1 R2 R3 R4 Total Signature
(3 Marks) (3 Marks) (3 Marks) (1 Mark) (10 Marks)
EXPERIMENT NO: 11
Date of Performance :

Date of Submission :

AIM: To explore Threading using python.

THEORY:
Threading allows you to have different parts of your process run concurrently These different parts are
usually individual and have a separate unit of execution belonging to the same process. The process is
nothing but a running program that has individual units that can be run concurrently. For example, A web-
browser could be a process, an application running multiple cameras simultaneously could be a process;
a video game is another example of a process.

Inside a process comes the concept of multiple threading or commonly known as multi-threading, where
multiple threads work together to achieve a common goal. The most crucial benefit of using threads is that
it allows you to run the program in parallel.

Threading in Python

● In Python, the threading module is a built-in module which is known as threading and can be
directly imported.
● Since almost everything in Python is represented as an object, threading also is an object in
Python. A thread is capable of
o Holding data,
o Stored in data structures like dictionaries, lists, sets, etc.
o Can be passed as a parameter to a function.

● A thread can also be executed as a process.


● A thread in Python can have various states like:
o Wait,
o Locked.

Starting a New Thread

To spawn another thread, you need to call following method available in thread module −

thread.start_new_thread ( function, args[, kwargs] )

This method call enables a fast and efficient way to create new threads in both Linux and Windows.

The method call returns immediately and the child thread starts and calls function with the passed list of
args. When function returns, the thread terminates.
Here, args is a tuple of arguments; use an empty tuple to call function without passing any arguments.
kwargs is an optional dictionary of keyword arguments.

Example

#!/usr/bin/python

import
thread
import
time

# Define a function for the


thread def print_time(
threadName, delay):
count = 0
while count < 5:
time.sleep(del
ay) count +=
1
print "%s: %s" % ( threadName, time.ctime(time.time()) )

# Create two threads as


follows try:
thread.start_new_thread( print_time, ("Thread-1", 2,
) ) thread.start_new_thread( print_time, ("Thread-
2", 4, ) )
except:
When
printthe"Error:
aboveunable
code istoexecuted, it produces the following result −
start thread"

w
Thread-1: Thu Jan 22 15:42:17 2009
hil
Thread-1: Thu Jan 22 15:42:19 2009
e
Thread-2: Thu Jan 22 15:42:19 2009
1:
Thread-1: Thu Jan 22 15:42:21 2009
pas
Thread-2: Thu Jan 22 15:42:23 2009
s
Thread-1: Thu Jan 22 15:42:23 2009
Thread-1: Thu Jan 22 15:42:25 2009
Thread-2: Thu Jan 22 15:42:27 2009
Thread-2: Thu Jan 22 15:42:31 2009
Thread-2: Thu Jan 22 15:42:35 2009

The Threading Module

The newer threading module included with Python 2.4 provides much more powerful, high-level support
for threads than the thread module discussed in the previous section.
The threading module exposes all the methods of the thread module and provides some additional
methods −

● threading.activeCount() − Returns the number of thread objects that are active.


● threading.currentThread() − Returns the number of thread objects in the caller's thread control.
● threading.enumerate() − Returns a list of all thread objects that are currently active.

In addition to the methods, the threading module has the Thread class that implements threading. The
methods provided by the Thread class are as follows −

● run() − The run() method is the entry point for a thread.


● start() − The start() method starts a thread by calling the run method.
● join([time]) − The join() waits for threads to terminate.
● isAlive() − The isAlive() method checks whether a thread is still executing.
● getName() − The getName() method returns the name of a thread.
● setName() − The setName() method sets the name of a thread.

Multithreaded Priority Queue


The Queue module allows you to create a new queue object that can hold a specific number of items.
There are following methods to control the Queue −

● get() − The get() removes and returns an item from the queue.
● put() − The put adds item to a queue.
● qsize() − The qsize() returns the number of items that are currently in the queue.
● empty() − The empty( ) returns True if queue is empty; otherwise, False.
● full() − the full() returns True if queue is full; otherwise, False.

import threading
# Function to calculate volume of cube
def cube_volume(side):
volume = side ** 3
print(f"Volume of cube with side {side} is {volume}")

# Function to calculate volume of square


def square_area(side):
area = side ** 2
print(f"Area of square with side {side} is {area}")

if __name__ == "__main__":
# Input side length
side = float(input("Enter the side length: "))

# Create threads
cube_thread = threading.Thread(target=cube_volume, args=(side,))
square_thread = threading.Thread(target=square_area, args=(side,))

# Start threads
cube_thread.start()
square_thread.start()
# Wait for threads to finish
cube_thread.join()
square_thread.join()

print("Calculation completed.")

CONCLUSION: Program executed successfully

R1 R2 R3 R4 Total Signature
(3 Marks) (3 Marks) (3 Marks) (1 Mark) (10 Marks)
EXPERIMENT NO: 12
Date of Performance :

Date of Submission :

AIM: Program to demonstrate CRUD (create, read, update and delete)


operationson database (SQLite/MySQL) usingpython

SOFTWARE REQUIREMENT: Python

THEORY:

The Python standard for database interfaces is the Python DB-API. Most Python database
interfaces adhere to this standard. Python Database API supports a wide range of database
servers such as −

● GadFly

● mSQL

● MySQL

● PostgreSQL

● Microsoft SQL Server2000

● Informix

● Interbase

● Oracle

● Sybase

The DB API provides a minimal standard for working with databases using Python structures
and syntax wherever possible. This API includes the following −

● Importing the APImodule.

● Acquiring a connection with thedatabase.

● Issuing SQL statements and storedprocedures.

● Closing theconnection
MySQLdb
MySQLdb is an interface for connecting to a MySQL database server from Python. It implements
the Python Database API v2.0 and is built on top of the MySQL C AP

Database Connection
Before connecting to a MySQL database, make sure of the followings −

● You have created a databaseTESTDB.

● You have created a table EMPLOYEE inTESTDB.

● This table has fields FIRST_NAME, LAST_NAME, AGE, SEX andINCOME.

● User ID "testuser" and password "test123" are set to accessTESTDB.

● Python module MySQLdb is installed properly on yourmachine.

● You have gone through MySQL tutorial to understand MySQLBasics.

If a connection is established with the datasource, then a Connection Object is returned and saved
into db for further use, otherwise db is set to None. Next, db object is used to create a cursor
object, which in turn is used to execute SQL queries. Finally, before coming out, it ensures that
database connection is closed and resources are released.

Creating Database Table


Once a database connection is established, we are ready to create tables or records into the
database tables using execute method of the createdcursor.

Example
Let us create Database table EMPLOYEE −

#!/usr/bin/python
import MySQLdb
# Open database connection
db = MySQLdb.connect("localhost","testuser","test123","TESTDB" )

cursor = db.cursor()
# Drop table if it already exist using execute() method.
cursor.execute("DROP TABLE IF EXISTS EMPLOYEE")
# Create table as per requirement
sql = """CREATE TABLE EMPLOYEE (
FIRST_NAME CHAR(20) NOT NULL,
LAST_NAME CHAR(20),
AGE INT,
SEX CHAR(1),
INCOME FLOAT )"""
cursor.execute(sql)
# disconnect from server
db.close()

INSERT Operation
It is required when you want to create your records into a database table.

sql = """INSERT INTO

EMPLOYEE(FIRST_NAME, LAST_NAME,

AGE, SEX, INCOME)

VALUESREAD
('Mac',Operation
'Mohan', 20, 'M', 2000)"""
READ Operation on any database means to fetch some useful information from the database.

Once our database connection is established, you are ready to make a query into this database.
You can use either fetchone() method to fetch single record or fetchall() method to fetech
multiple values from a database table.

● fetchone() − It fetches the next row of a query result set. A result set is an object that is
returned when a cursor object is used to query atable.

● fetchall() − It fetches all the rows in a result set. If some rows have already been
extracted from the result set, then it retrieves the remaining rows from the resultset.

● rowcount − This is a read-only attribute and returns the number of rows that were
affected by an execute()method.

sql = "SELECT * FROM EMPLOYEE \

WHERE INCOME > '%d'" % (1000)


Update Operation
UPDATE Operation on any database means to update one or more records, which are already
available in the database.

sql = "UPDATE EMPLOYEE SET AGE = AGE + 1

WHERE GENDER = '%c'" %('M')


DELETE Operation
DELETE operation is required when you want to delete some records from your database.
Following is the procedure to delete all the records from EMPLOYEE where AGE is more than 20

sql = "DELETE FROM EMPLOYEE WHERE AGE > '%d'" % (20)



import sqlite3
conn = sqlite3.connect('example.db')
cursor = conn.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS users
(id INTEGER PRIMARY KEY, name TEXT, email TEXT)''')
cursor.execute("INSERT INTO users (name, email) VALUES ('Alice', '[email protected]')")
cursor.execute("INSERT INTO users (name, email) VALUES ('Bob', '[email protected]')")
cursor.execute("INSERT INTO users (name, email) VALUES ('Charlie', '[email protected]')")
conn.commit()
cursor.execute("SELECT * FROM users")
rows = cursor.fetchall()
for row in rows:
print(row)
cursor.execute("UPDATE users SET email = '[email protected]' WHERE name = 'Alice'")
conn.commit()
cursor.execute("SELECT * FROM users")
rows = cursor.fetchall()
for row in rows:
print(row)
cursor.execute("DELETE FROM users WHERE name = 'Bob'")
conn.commit()

cursor.execute("SELECT * FROM users")


rows = cursor.fetchall()
for row in rows:
print(row)
cursor.close()
conn.close()
(before update and delete):

(after update):

(after delete):

CONCLUSION: Program executed successfully

R1 R2 R3 R4 Total Signature
(3 Marks) (3 Marks) (3 Marks) (1 Mark) (10 Marks)

You might also like