ISBN: 978-93-343-4562-9
© 2025 Bhakti P. Patil
All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any
form or by any means-electronic, mechanical, photocopying, recording, or otherwise-without the
prior written permission of the author, except in the case of brief quotations used for review or
scholarly purposes.
This book is intended for educational purposes only. While every effort has been made to ensure
the accuracy of the information within, the author and publisher assume no responsibility for errors,
omissions, or damages resulting from the use of the material contained herein.
Python® is a registered trademark of the Python Software Foundation. All trademarks mentioned
belong to their respective owners and are used for educational purposes only.
First Edition: August 2025
Printed in India
ISBN: 978-93-343-4562-9
Cover design by: Bhakti [Link]
Published by: Self-Published
ISBN: 978-93-343-4562-9
Dedication
To my dearest daughter,
whose innocent smile and boundless love fill my heart with purpose and strength.
To my beloved parents,
whose sacrifices, wisdom, and endless support have been the guiding light of my journey.
To my gracious in-laws,
whose blessings, kindness, and quiet encouragement have uplifted me at every step.
And to my loving husband,
my constant companion and source of strength—thank you for believing in me, even when I
doubted myself.
ISBN: 978-93-343-4562-9
Syllabus
Minor in Data Science
(Sem.- III)
Title of Paper: Python for Data Science
Sr Heading Particulars
No.
Description of the Advanced python programming practical modules
course : make able to acquire knowledge for implementing
python code for various applications such as handling
data, analysing and visualizing data. Database
Including but Not Management System’s practical approach is useful to
limited to : gain the knowledge for software backend
development. It benefits to user by providing data
definition, data access, reduced data redundancy, data
integrity, data sharing, data organizing, data
consistency, data accuracy, and security.
Vertical : Minor
Type : Practical
Credit: 2 credits (1 credit = 15 Hours for Theory or 30 Hours
of Practical work in a semester)
Hours Allotted : 30 Hours
Marks Allotted: 50 Marks
Course Objectives:
1. Implement Python for Data Processing – Utilize tuples, regular
expressions, date-time functions, and libraries like NumPy and Pandas
for data manipulation.
2. Understand Relational Databases & SQL – Identify entities,
ISBN: 978-93-343-4562-9
relationships, and relational structures while implementing constraints
using SQL.
3. Perform Data Retrieval & Manipulation in SQL – Execute DML
operations, apply built-in functions, retrieve and aggregate data, and
work with joins and nested queries.
4. Manage Database Security & Access Control – Implement user
access controls, security measures, and database backup strategies.
Course Outcomes:
1. Apply Python for Data Handling – Utilize lists, tuples, regular
expressions, date-time functions, and libraries like NumPy and Pandas
for data processing.
2. Execute SQL Queries for Data Operations – Perform CRUD
(Create, Read, Update, Delete) operations, table modifications, and
database backup/restoration using SQL.
3. Retrieve & Analyze Data Using SQL – Use aggregate functions,
joins, and nested queries to extract meaningful insights from relational
databases.
4. Manage Database Security & Optimization – Implement access
control, create virtual tables, and optimize database structures for
secure and efficient data management.
ISBN: 978-93-343-4562-9
INDEX
Sr No Title Page No
Module I
1 A Write a python code to print your profile. 1
B write a python code to print addition of two numbers. 3
C Write a python code to print square root of number. 4
D Write a python code to calculate area of Triangle. 5
E Write a python code to swap two variables. 6
2 A Write a python code to create nested tuples. 7
B Write a python code to sort the nested tuple using 11
sorted() function.
C Write a python code to copy or clone list. 13
D Write a python code to check immutability property of 15
python tuples.
3 A Write a python code for creating a variable and storing 17
the text that we want to search
B Write a python code to retrieve data from HTML file. 18
C Write a python code to print current date in different 19
format.
D Write a python code to convert time stamp to date 20
stamp.
E Write a python code to develop calendar module. 21
F Write a python code to compare two dates. 22
Module II
4 A Write a python code to create Numpy Array. 24
B Write a python code to demonstrate basic operations 25
on single array.
C Write a python code to create array with 10 elements 26
and slice element from 1st to 5th element.
ISBN: 978-93-343-4562-9
Write a python code to sort an array alphabetically. 27
Write a python code to create a filter array that will 28
return maximum values from an array.
5 A Write a python code to demonstrate importing pandas 29
libraries and create data frame object.
B Write a python code to show statistical information on 30
given data set.
C Write a python code to create pandas series from 31
dictionaries.
D Write a python code to demonstrate filter pandas 32
series with Boolean arrays.
***
ISBN: 978-93-343-4562-9
Practical No. 1
A. Write a python code to print your profile.
Algorithm
Step 1: start
Step 2: using “print()” function print required details.
Step 3: end
Python Code
# Program to print a short CV using Python
name = "Bhakti P. Patil"
email = "bhakti@[Link]"
phone = "+91-9876543210"
qualification = "[Link]. IT, NET,SET"
skills = ["Python", "NumPy", "Pandas", "Data Analysis"]
experience = "1 year internship in Data Science"
print("========== CURRICULUM VITAE ==========")
print("Name :", name)
print("Email :", email)
print("Phone :", phone)
print("Qualification:", qualification)
print("Skills :", ', '.join(skills))
print("Experience :", experience)
print("======================================")
1
ISBN: 978-93-343-4562-9
Expected Output
========== CURRICULUM VITAE ==========
Name : Bhakti Raut
Email : bhakti@[Link]
Phone : +91-9876543210
Qualification: [Link]. IT
Skills : Python, NumPy, Pandas, Data Analysis
Experience : 1 year internship in Data Science
Explanation
[Link](): This is built -in function in python. The print() function displays the specified
message or data on the screen. You can print text (strings), numbers, variables, or even
complex data structures like lists, arrays, or DataFrames.
2. ', '.join(skills) joins the list of skills into a single comma-separated string.
2
ISBN: 978-93-343-4562-9
B. write a python code to print addition of two numbers.
Python Code 1:
a = 10
b = 20
print("Addition:", a + b)
Python Code 2:
# Program to add two numbers
# Taking input from the user
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
# Adding the numbers
sum = num1 + num2
# Displaying the result
print("The sum of", num1, "and", num2, "is:", sum)
Expected Output
Enter first number: 10.5
Enter second number: 20
The sum of 10.5 and 20.0 is: 30.5
3
ISBN: 978-93-343-4562-9
Explanation
• input() function takes input from the user as a string.
• float() converts that string input into a floating-point number (to support decimal
values).
• + operator adds the two numbers.
• print() displays the result on the screen.
C. Write a python code to print square root of number.
Algorithm :
Step 1: Start
Step 2: Input a number from the user and store it in num.
Step 3: Compute the square root of num using the [Link]() function.
Step 4: Display the result.
Step 5: End
Python Code :
import math
# Input from user
num = float(input("Enter a number: "))
# Calculate square root
sqrt = [Link](num)
# Display result
print("Square root of", num, "is", sqrt)
Expected Output:
4
ISBN: 978-93-343-4562-9
Enter a number: 16
Square root of 16.0 is 4.0
Explanation
• import math gives access to mathematical functions.
• [Link]() is a built-in function that returns the square root.
• float(input()) allows decimal inputs.
D. Write a python code to calculate area of Triangle.
Algorithm :
Step 1: Start
Step 2: Input base of the triangle and store it in base.
Step 3: Input height of the triangle and store it in height.
Step 4: Calculate area using the formula:
area = 0.5 × base × height
Step 5: Display the area.
Step 6: End
Python Code
# Input base and height from user
base = float(input("Enter base of the triangle: "))
height = float(input("Enter height of the triangle: "))
# Calculate area
area = 0.5 * base * height
# Display result
print("Area of the triangle is:", area)
5
ISBN: 978-93-343-4562-9
Expected Output:
Area of Triangle: 25.0
Explanation :
• Inputs: The user enters the base and height as float values (to allow decimal
input).
• Formula: Area = ½ × base × height
• The program multiplies base and height, then multiplies by 0.5.
• print() displays the result.
E. Write a python code to swap two variables.
Algorithm
Step 1: Start
Step 2: input a number and store it in “a”
Step 3: input a number and store it in “b”
Step 4: print message “Before swap, values of a and b : ”
Step 5: swap both number
Step 6: print message “After swap, values of a and b : ”
Step 7: End
Python Code
x=5
y = 10
print("Before swap: x =", x, "y =", y)
x, y = y, x
print("After swap: x =", x, "y =", y)
Expected Output
Before swap: x = 5 y = 10
After swap: x = 10 y = 5
6
ISBN: 978-93-343-4562-9
7
ISBN: 978-93-343-4562-9
Practical No. 2
A. Write a python code to create nested tuples.
Tuple: In Python, a tuple is a built-in data type used to store multiple items in a single
variable. A tuple is ordered, immutable (unchangeable), and can contain elements of
different data types (e.g., strings, integers, lists, even other tuples).
Key Characteristics of Tuples:
Property Description
Ordered The items have a defined order, and it won't change.
Immutable Once a tuple is created, its elements cannot be changed.
Allow Duplicates Tuples can contain duplicate values.
Indexable You can access items by their index position.
Algorithm:
Step 1: Start
Step 2: Create tuples with various data types.
Step 3: Access elements using indices.
Step 4: Perform packing and unpacking.
Step 5: Use built-in functions like len().
Step 6: Demonstrate tuple concatenation and repetition.
Step 7: Check membership using in operator.
Step 8: Create and display nested tuples.
Step 9: End
8
ISBN: 978-93-343-4562-9
Python Code
# Creating a tuple
my_tuple = (10, "apple", 3.14)
# A tuple with one item (use a comma!)
single_item = ("hello",)
Accessing Tuple Elements:
print(my_tuple[0]) # Output: 10
print(my_tuple[-1]) # Output: 3.14
Tuple Packing and Unpacking:
# Packing
person = ("Alice", 25, "Engineer")
# Unpacking
name, age, profession = person
print(name) # Output: Alice
print(profession) # Output: Engineer
# Length of a tuple
len(my_tuple) # 3
# Concatenation
t1 = (1, 2)
t2 = (3, 4)
t3 = t1 + t2 # (1, 2, 3, 4)
9
ISBN: 978-93-343-4562-9
# Repetition
t4 = t1 * 2 # (1, 2, 1, 2)
# Membership test
print(2 in t1) # True
# Creating nested tuples
student1 = ("Alice", 21)
student2 = ("Bob", 22)
student3 = ("Charlie", 20)
# Tuple containing other tuples
students = (student1, student2, student3)
# Display nested tuple
print("Nested Tuple of Students:")
print(students)
Expected Output:
Nested Tuple of Students:
10
ISBN: 978-93-343-4562-9
(('Alice', 21), ('Bob', 22), ('Charlie', 20))
Explanation :
• A tuple is an ordered and immutable collection.
• Here, each student is a tuple with (name, age).
• students is a tuple that contains multiple tuples, forming a nested tuple.
• print() displays the full nested structure.
11
ISBN: 978-93-343-4562-9
B. Write a python code to sort the nested tuple using sorted()
function.
Algorithm
Step 1: Start
Step 2: Define a nested tuple
Step 3: Sort the nested tuple by the first element of each inner tuple (numeric order)
Step 4: Display the result
Step 5: Sort the nested tuple by the second element of each inner tuple (alphabetical
order)
Step 6: Display the result
Step 7: End
Python Code
# Original nested tuple
nested_tuple = ((3, 'banana'), (1, 'apple'), (4, 'cherry'), (2, 'date'))
# Sorting by the first element of each inner tuple
sorted_by_first = tuple(sorted(nested_tuple))
print("Sorted by first element:")
print(sorted_by_first)
# Sorting by the second element (alphabetically)
sorted_by_second = tuple(sorted(nested_tuple, key=lambda x: x[1]))
12
ISBN: 978-93-343-4562-9
print("\nSorted by second element:")
print(sorted_by_second)
Expected Output
Sorted nested tuples: [(1, 4), (2, 2), (3, 1)]
Explanation:
• sorted(nested_tuple): Sorts based on the first item of each inner tuple by default.
• key=lambda x: x[1]: Tells sorted() to sort based on the second item in each inner
tuple.
• tuple(): Converts the sorted list back into a tuple, since sorted() always returns a list.
13
ISBN: 978-93-343-4562-9
C. Write a python code to copy or clone list.
Algorithm:
Step 1: Start with an original list.
Step 2: Use a method to copy the original list to a new one.
Step 3: Modify one list to check if the copy is independent.
Step 4: Print both lists.
Step 5: End
Python Code
# Method 1: Using [Link]()
original_list = [10, 20, 30, 40, 50]
cloned_list1 = original_list.copy()
print("Original List", original_list)
print("Cloned using copy():", cloned_list1)
# Method 2: Using slicing [:]
cloned_list2 = original_list[:]
print("Cloned using slicing:", cloned_list2)
# Method 3: Using list() constructor
cloned_list3 = list(original_list)
print("Cloned using list():", cloned_list3)
# Method 4: Using copy module (for deep copy, useful for nested lists)
import copy
original_nested_list = [[1, 2], [3, 4]]
14
ISBN: 978-93-343-4562-9
deep_cloned_list = [Link](original_nested_list)
print("Original nested list:", original_nested_list)
print("Deep cloned list:", deep_cloned_list)
Expected Output
Cloned using copy(): [10, 20, 30, 40, 50]
Cloned using slicing: [10, 20, 30, 40, 50]
Cloned using list(): [10, 20, 30, 40, 50]
Original nested list: [[1, 2], [3, 4]]
Deep cloned list: [[1, 2], [3, 4]]
Explanation :
• [Link]() → Returns a shallow copy of the list.
• [:] → List slicing from beginning to end creates a new copy.
• list() → Type conversion to a new list.
• [Link]() → Creates a deep copy, useful when the list has nested lists (inner
lists).
15
ISBN: 978-93-343-4562-9
D. Write a python code to check immutability property of
python tuples.
Algorithm :
Step 1: Create a tuple with some values.
Step 2: Try to modify an element of the tuple (e.g., change value at a specific index).
Step 3: Try to append or delete an element from the tuple.
Step 4: Use try...except block to catch and print the exception showing immutability.
Step 5: Print results and error messages.
Python Code
# Step 1: Create a tuple
my_tuple = (10, 20, 30)
print("Original tuple:", my_tuple)
# Step 2: Try modifying an element
try:
my_tuple[1] = 99
except TypeError as e:
print("Error while modifying tuple:", e)
# Step 3: Try appending an element
try:
my_tuple.append(40)
except AttributeError as e:
print("Error while appending to tuple:", e)
16
ISBN: 978-93-343-4562-9
# Step 4: Try deleting an element
try:
del my_tuple[0]
except TypeError as e:
print("Error while deleting from tuple:", e)
# Final check
print("Tuple after all operations:", my_tuple)
Expected Output
Original tuple: (10, 20, 30)
Error while modifying tuple: 'tuple' object does not support item assignment
Error while appending to tuple: 'tuple' object has no attribute 'append'
Error while deleting from tuple: 'tuple' object doesn't support item deletion
Tuple after all operations: (10, 20, 3
Explanation :
• tuple[1] = value → Raises TypeError because you can’t modify a tuple.
• [Link]() → Tuples don’t have this method, raises AttributeError.
• del tuple[index] → You can't delete individual items from a tuple.
17
ISBN: 978-93-343-4562-9
Practical No. 3
A. Write a python code for creating a variable and storing the
text that we want to search
Algorithm
Step 1: Start
Step 2: Set text and search
Step 3: If search is in text → print "search found"
Step 4: Else → print "search not found"
Step 5: Stop
Python Code
text = "Python is a powerful programming language."
search = "powerful"
if search in text:
print(f"{search!r} found in the text.")
else:
print(f"{search!r} not found in the text.")
Expected Output
'powerful' found in the text.
18
ISBN: 978-93-343-4562-9
B. Write a python code to retrieve data from HTML file
Algorithm
Step 1: Start.
Step 2: Import the BeautifulSoup module from bs4.
Step 3: Open the HTML file in read mode.
Step 4: Read the file content into a string.
Step 5: Create a BeautifulSoup object and parse the HTML content.
Step 6: Use find() or find_all() to locate the required HTML tags or attributes.
Step 7: Extract and store the text or attribute values.
Step 8: Print or return the extracted data.
Step 9: End.
Python Code
# Step 1: Import library
from bs4 import BeautifulSoup
# Step 2: Open and read the HTML file
with open("[Link]", "r", encoding="utf-8") as file:
html_content = [Link]()
# Step 3: Parse HTML content
soup = BeautifulSoup(html_content, "[Link]")
# Step 4: Example - retrieve all paragraph texts
paragraphs = soup.find_all("p")
for p in paragraphs:
print("Paragraph:", p.get_text())
# Step 5: Example - retrieve all links
links = soup.find_all("a")
for link in links:
print("Link Text:", link.get_text(), "| URL:", [Link]("href"))
Expected Output
Paragraph: This is the first paragraph.
Paragraph: This is the second paragraph with a link.
19
ISBN: 978-93-343-4562-9
Link Text: link | URL: [Link]
C. Write a python code to print current date in different
format.
Algorithm
Step 1: Start.
Step 2: Import the datetime class from the datetime module.
Step 3: Retrieve the current date and time using [Link]() and store it in a variable
now.
Step 4: Format the date in DD/MM/YYYY format using strftime("%d/%m/%Y") and
print it.
Step 5: Format the date in Month DD, YYYY format using strftime("%B %d, %Y") and
print it.
Step 6: Format the date in YYYY-MM-DD format using strftime("%Y-%m-%d") and
print it.
Step 7: End
Python Code
from datetime import datetime
now = [Link]()
print("Format 1 (DD/MM/YYYY):", [Link]("%d/%m/%Y"))
print("Format 2 (Month DD, YYYY):", [Link]("%B %d, %Y"))
print("Format 3 (YYYY-MM-DD):", [Link]("%Y-%m-%d"))
Expected Output
Format 1 (DD/MM/YYYY): 19/06/2025
Format 2 (Month DD, YYYY): June 19, 2025
Format 3 (YYYY-MM-DD): 2025-06-19
20
ISBN: 978-93-343-4562-9
D. Write a python code to convert time stamp to date stamp.
Algorithm
Step 1: Start.
Step 2: Import the datetime module.
Step 3: Store the timestamp value in a variable.
Step 4: Use [Link](timestamp) to convert the timestamp into a
datetime object.
Step 5: Format the datetime object into a readable date using strftime() with the desired
format (e.g., "%Y-%m-%d").
Step 6: Print the date stamp.
Step 7: End.
Python Code
from datetime import datetime
# Step 3: Example timestamp (seconds since 1970-01-01 UTC)
timestamp = 1691750400 # Example: corresponds to 2023-08-11
# Step 4: Convert timestamp to datetime object
dt_object = [Link](timestamp)
# Step 5: Format as date stamp (YYYY-MM-DD)
date_stamp = dt_object.strftime("%Y-%m-%d")
# Step 6: Print result
print("Timestamp:", timestamp)
print("Date Stamp:", date_stamp)
Expected Output
Timestamp: 1691750400
Date Stamp: 2023-08-11
21
ISBN: 978-93-343-4562-9
E. Write a python code to develop calendar module.
Algorithm
Step 1: Start.
Step 2: Import the calendar module.
Step 3: Set the year variable to 2025.
Step 4: Set the month variable to 6 (June).
Step 5: Use the function [Link](year, month) to get a string representation of the
specified month’s calendar.
Step 6: Print the month’s calendar.
Step 7: End.
Python Code
import calendar
year = 2025
month = 6
print([Link](year, month))
Expected Output
June 2025
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
22
ISBN: 978-93-343-4562-9
f. Write a python code to compare two dates.
Algorithm
Step 1: Start.
Step 2: Import the date class from the datetime module.
Step 3: Create a date object date1 with the value 2025-06-19.
Step 4: Create a date object date2 with the value 2025-06-20.
Step 5: Compare date1 and date2 using the < operator.
If date1 is earlier than date2, display "date1 is earlier than date2".
Step 6: Compare date1 and date2 using the > operator.
If date1 is later than date2, display "date1 is later than date2".
Step 7: If neither condition is true, display "Both dates are equal".
Step 8: End.
Python Code
from datetime import date
date1 = date(2025, 6, 19)
date2 = date(2025, 6, 20)
if date1 < date2:
print("date1 is earlier than date2")
elif date1 > date2:
print("date1 is later than date2")
else:
print("Both dates are equal")
Expected Output
date1 is earlier than date
23
ISBN: 978-93-343-4562-9
Module II
24
ISBN: 978-93-343-4562-9
Practical No 4
A. Write a python code to create Numpy Array.
Algorithm
1. Start
2. Import the numpy library as np
3. Create a numpy array using [Link]() function
4. Print the created array
5. End
Program
import numpy as np
arr = [Link]([1, 2, 3, 4, 5])
print(arr)
Expected Output:
[1 2 3 4 5]
Explanation:
This program creates a one-dimensional NumPy array containing integers from 1 to 5.
NumPy arrays are used for fast mathematical operations.
25
ISBN: 978-93-343-4562-9
B. Write a python code to demonstrate basic operations on
single array.
Algorithm
1. Start
2. Import numpy library as np
3. Create a numpy array
4. Perform operations such as addition, multiplication, mean calculation
5. Print results
6. End
Program
import numpy as np
arr = [Link]([1, 2, 3, 4, 5])
print("Addition:", arr + 2)
print("Multiplication:", arr * 2)
print("Mean:", [Link](arr))
Expected Output:
Addition: [3 4 5 6 7]
Multiplication: [ 2 4 6 8 10]
Mean: 3.0
Explanation
Demonstrates element-wise addition and multiplication, as well as calculating the
mean of the array.
26
ISBN: 978-93-343-4562-9
C. Write a python code to create array with 10 elements and
slice element from 1st to 5th element.
Algorithm
1. Start
2. Import numpy library as np
3. Create an array with 10 elements
4. Slice elements from index 0 to 4 (1st to 5th element)
5. Print sliced elements
6. End
Program
import numpy as np
arr = [Link]([10, 20, 30, 40, 50, 60, 70, 80, 90, 100])
print(arr[0:5])
Expected Output
[10 20 30 40 50]
Explanation:
Slices the first five elements from a 10-element array.
27
ISBN: 978-93-343-4562-9
D. Write a python code to sort an array alphabetically.
Algorithm
1. Start
2. Import numpy library as np
3. Create an array of strings
4. Sort the array using [Link]()
5. Print the sorted array
6. End
Program
import numpy as np
arr = [Link](['banana', 'apple', 'cherry', 'date'])
print([Link](arr))
Expected Output
['apple' 'banana' 'cherry' 'date']
Explanation:
Sorts an array of strings in alphabetical order.
28
ISBN: 978-93-343-4562-9
E. Write a python code to create a filter array that will return
maximum values from an array.
Algorithm
1. Start
2. Import numpy library as np
3. Create an array of numbers
4. Find maximum value using [Link]()
5. Create a filter to select only maximum values
6. Print the filtered array
7. End
Program
import numpy as np
arr = [Link]([1, 3, 7, 7, 2, 5])
max_val = [Link](arr)
filtered = arr[arr == max_val]
print(filtered)
Expected Output
[7 7]
Explanation: Finds the maximum number in the array and returns all occurrences of it.
29
ISBN: 978-93-343-4562-9
Practical No 5
A. Write a python code to demonstrate importing pandas
libraries and create data frame object.
Algorithm
1. Start
2. Import pandas library as pd
3. Create a dictionary with data
4. Convert dictionary to DataFrame using [Link]()
5. Print DataFrame
6. End
Program
import pandas as pd
data = {'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [25, 30, 35]}
df = [Link](data)
print(df)
Expected Output:
Name Age
0 Alice 25
1 Bob 30
2 Charlie 35
Explanation: Creates a pandas DataFrame from a Python dictionary.
30
ISBN: 978-93-343-4562-9
B. Write a python code to show statistical information on given
data set.
Algorithm
1. Start
2. Import pandas as pd
3. Create a DataFrame
4. Use describe() to get statistical summary
5. Print summary
6. End
Program
import pandas as pd
data = {'Age': [25, 30, 35, 40, 45]}
df = [Link](data)
print([Link]())
Expected Output
Age
count 5.000000
mean 35.000000
std 7.905694
min 25.000000
25% 30.000000
50% 35.000000
75% 40.000000
max 45.000000
Explanation: Displays count, mean, standard deviation, min, and max values for the
dataset.
31
ISBN: 978-93-343-4562-9
C. Write a python code to create pandas series from
dictionaries.
Algorithm
1. Start
2. Import pandas as pd
3. Create a dictionary
4. Convert to Series using [Link]()
5. Print Series
6. End
Program
import pandas as pd
data = {'a': 10, 'b': 20, 'c': 30}
series = [Link](data)
print(series)
Expected Output:
a 10
b 20
c 30
dtype: int64
32
ISBN: 978-93-343-4562-9
D. Write a python code to demonstrate filter pandas series with
Boolean arrays.
Algorithm
1. Start
2. Import pandas as pd
3. Create a pandas Series
4. Apply boolean condition to filter data
5. Print filtered Series
6. End
Program
import pandas as pd
series = [Link]([10, 20, 30, 40, 50])
filtered = series[series > 25]
print(filtered)
Expected Output:
2 30
3 40
4 50
dtype: int64
Explanation: Filters the Series to include only values greater than 25.
33
ISBN: 978-93-343-4562-9
1
ISBN: 978-93-343-4562-9