0% found this document useful (0 votes)
6 views8 pages

Info Practical 1234 - DONE & SENT

The document provides a series of practical exercises using the Pandas library in Python, focusing on creating and manipulating Series. It includes examples of creating Series from lists and dictionaries, performing arithmetic operations on Series, and retrieving data based on specific conditions. Each program is accompanied by code snippets demonstrating the operations and expected outputs.

Uploaded by

ahkt9882
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views8 pages

Info Practical 1234 - DONE & SENT

The document provides a series of practical exercises using the Pandas library in Python, focusing on creating and manipulating Series. It includes examples of creating Series from lists and dictionaries, performing arithmetic operations on Series, and retrieving data based on specific conditions. Each program is accompanied by code snippets demonstrating the operations and expected outputs.

Uploaded by

ahkt9882
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

PRACTICAL-1

Pandas Series

DATA SERIES -PROGRAM- 1


1. Write a program in python to perform the following operations:
a) To create a Series from a list with values :
ONE, TWO, THREE, FOUR, FIVE, SIX

b) To print the series with default index values.

c) To print the series and give it the index values of ‘a’,’b’,’c’,’d’,’e’,’f’

PROGRAM:
import pandas as pd
print ("Printing series with default index values")
s1= pd.Series(["ONE","TWO","THREE","FOUR","FIVE","SIX"])
print (s1)
print("Printing series with explicitly defined index values")
s1.index= ['a', 'b', 'c', 'd', 'e', 'f']
print (s1)
OR
import pandas as pd
print ("Printing series with default index values")
s1= pd.Series(["ONE","TWO","THREE","FOUR","FIVE","SIX"])
print (s1)
print("Printing series with explicitly defined index values")
s1= pd.Series(["ONE","TWO","THREE","FOUR","FIVE","SIX"],
index= ['a', 'b', 'c', 'd', 'e', 'f'])
print (s1)

Page | 1
2. To create a pandas series from a dictionary of values:
D1={‘a’:100,’b’:200,’c’:300,’d’:400,’e’:500}

PROGRAM:
import pandas as pd
D1={'a':100, 'b':200, 'C': 300, 'd': 400, 'e':500}
print("ORIGINAL DICTIONARY")
print (D1)
S1=pd.Series (D1)
print("DICTIONARY CONVERTED TO SERIES")
print (S1)

OUTPUT:

Page | 2
PRACTICAL-2
Pandas Series

DATA SERIES -PROGRAM- 2


Q- Write a program in python to perform basic arithmetic operations such as
addition, substraction, multiplication, division and integer division on two series
S1 and S2 with given values S1=[10,20,30,40,50] , S2=[2,4,6,8,10]

PROGRAM:
import pandas as pd
s1 = pd.Series (range (10,60,10), index = [1, 2, 3, 4, 5])
s2 = pd.Series (range(2,11,2), index = [1, 2, 3, 4, 5])
print("Series s1:")
print (s1)
print("Series s2:")
print(s2)
print("Sum of 2 series:")
print(s1+s2)
print("difference of 2 series:")
print(s1-s2)
print("Product of 2 series:")
print(s1*s2)
print("Quotient of 2 series:")
print (s1/s2)
print("integer quotient of 2 series:")
print(s1//s2)

Page | 3
OUTPUT :

Page | 4
PRACTICAL-3
Pandas Series

DATA SERIES -PROGRAM- 3


Q- Write a program in python to perform the following operations:
a) To create a series from an array A of values
[10,20,30,40,50,60,70,80,90,100]
Without arange function with index values
[‘A’,’B’,’C’,’D’,’E’,’F’,’G’,’H’,’I’,’J’]
PROGRAM:
import pandas as pd
import numpy as np
A=np.array([10,20,30,40,50,60,70,80,90,100])
print("PRINTING ARRAY ELEMENTS")
print (A)
S=pd.Series (A, index=['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'])
print("PRINTING SERIES ELEMENT FROM ARRAY WITH
DEFINED INDEX VALUES")
print (S)

OUTPUT:

Page | 5
b) To create a series from an array A of values
[10,20,30,40,50,60,70,80,90,100]
With arange function with default index values.
PROGRAM:
import pandas as pd
import numpy as np
A=(np.arange(10,110,10))
print("PRINTING ARRAY ELEMENTS")
print (A)
S=pd.Series (A)
print("PRINTING SERIES ELEMENT FROM ARRAY")
print (S)

OUTPUT:

Page | 6
PRACTICAL-4
Pandas Series

DATA SERIES -PROGRAM- 4


Q- Write a program to retrieve MARKS in a Series S1 based on the conditions
given below:
The List of MARKS are [45.5, 67.75, 89.5, 33.25, 90.75, 70.0, 29.25, 95.5]
a)Display all marks with values less than or equal to 40.
b)Display all marks with values greater than or equal to 90.
c)Display all marks not less than 60.
d)Display all marks not above 40.
e)Display all the marks other than 70.

PROGRAM:
import pandas as pd
S1=pd.Series ([45.5,67.75,89.5,33.25,90.75,70.0,29.25,95.5])
print("PRINTING ORIGINAL SERIES")
print (S1)
print("MARKS LESS THAN OR EQUAL TO 40")
print (S1 [S1<=40])
print("MARKS GREATER THAN OR EQUAL TO 90")
print (S1 [S1>=90])
print("MARKS NOT LESS THAN 60")
print (S1 [S1>=60])
print("MARKS NOT ABOVE 40")
print (S1 [S1<=40])
print("MARKS NOT EQUAL TO 70")
print (S1 [S1!=70])

Page | 7
OUTPUT:

Page | 8

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy