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

Ch-1_Python_Pandas-_I(Series)_Programs[1]

The document contains a series of programming exercises focused on creating and manipulating Pandas Series in Python for a class on Informatics Practices. Each program outlines specific tasks such as creating empty and non-empty Series, performing mathematical operations, and modifying Series data. The exercises aim to enhance students' understanding of data handling using the Pandas library.

Uploaded by

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

Ch-1_Python_Pandas-_I(Series)_Programs[1]

The document contains a series of programming exercises focused on creating and manipulating Pandas Series in Python for a class on Informatics Practices. Each program outlines specific tasks such as creating empty and non-empty Series, performing mathematical operations, and modifying Series data. The exercises aim to enhance students' understanding of data handling using the Pandas library.

Uploaded by

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

Shree Krishna International School, Vapi

Informatics Practices
Std -12
Chapter-1
Python Pandas- I
Series
Programs
Program-1
Create a simple Pandas Series from a list:
a = [1, 7, 2]
Program-2 1. Create a Empty Series
Write a code to create a empty Series object i.e. having no values.
Assume that Pandas as alias name pd

Input

Output
Program-3 2. Creating a Non- Empty Series
Write a code to create a Series object using the python sequence
[4,6,8,10]. Assume that Pandas as alias name pd

Input

Output
Program-4

Write a code to create a Series object using the python sequence .


Assume that Pandas as alias name pd

Input

Output
Program-5

Write a code to create a Series object using the python sequence


[11,21,31,41]. Assume that Pandas as alias name pd

Input

Output
Program-6

Write a program to create a Series object using individual characters


‘o’, ‘h’, ‘o’. Assume that Pandas as alias name pd

Input

Output
Program-7

Write a program to create a Series object using string


:”So Funny”. Assume that Pandas as alias name pd

Input

Output
Program-8

Write a program to create a Series object using a dictionary


that stores the number of students in each section of class 12 in your
school .
Input

Output
Program-9
Write a program to create a Series object with data of no. students
as 40,41,39,42 for the section A,B,C,D of class 12 in your school .

Input

Output
Program-10

Write a program to create a Series object that stores the initial


budget allocated(50000/-each) for four quarter of the year:
Qtr1,Qtr2,Qyr3, Qtr4.
Input

Output
Program-11

Total number of medals to be won is 200 in the Inter University


games held every alternate year. Write a code to create series object
that stores these medals for games to be held in decade 2020-2029
Input

Output
Program-12

A python list namely section names(‘A’, ‘B’, ’C’, ‘D’) of class12 in your
school. Another list Conutri stores the contribution made by these
students to a charity fund enclosed by the school. Write a code to
create a series object that contribution amount as the values and
the section names as the indexes.
Input

Output
Program-13

Using mathematical function in Series, write a code to double the


value of the data and make square each data.

Input

Output
Program-13

Using mathematical function in Series, write a code to double the


value of the data and make square each data.

Input Output
Program-14

Using mathematical function in Series, write a code to when a data


multiplied with a list replicates the list.(Hint: 2* list)

Input Output
Program-15

Sequence section and contri1 store the section names (‘A’, ‘B’, ‘C’,
‘D’,’E) and contribution made by them respectively (6700, 5600,
5000,5200, nil) for a charity. Your school has decided to donate as
much contribution as made by each section i.e. the donation will be
doubled. Write code to create series object that stores the
contribution amount as the values and the section names as the
indexes with data type as float32

Input
Program-15
Output
Program-16

Create a series that stores the number of students in each section of


class 12 as 39,41,42,44. First two sections have been given task of
selling tickets @100/- per ticket as part of a social experiment. Write
a code to display how much they have collected.
Input Output
Program-17

Create a series that stores the number of students in each section of


class 11 as 40,42,41,44. First two sections have been given task of
selling tickets @100/- per ticket, third section have a task of selling
tickets @150 & fourth section @200/- as part of a social experiment.
Write a code to display how much they have collected.

Input Output
Program-18

Consider the series object s1that stores section names (‘A’, ‘B’, ‘C’,
‘D’) and contribution made by them respectively (6700, 5600,
5000,5200) for a charity. Write a code to modify the amount of
section ’A’ as 7600 and for sections ‘C’ & ‘D’ as 7000. print the
changed series object.
Input
Output
Program-19

A series object trdata consists of around 2500 rows of data. Write a


program to print the following details.
i)First 100 rows of data ii) Last 5 rows of data

Input
Program-20

Number of students in 11 and 12 in three streams(‘Science’,


‘Commerce’, Humanities’) are stored in two series objects c11
andc12. Write code to find total number of students in classes 11
and12, stream wise.

Input
Program-21

Create two series s1 and s2 and do the arithmetic calculations.(min 5


data elements)

Input
Output
Program-22

Object1 Population stores the details of population of four metro


cities of India. And object2 AvgIncome stores the total average
income reported in previous year in each of these metros. Calculate
income per capita for each of these metro cities.
Input
Output
Program-23

What will be the output produced by the following program?


import pandas as pd
info=pd.Series(data=[31,41,51])
print(info)
print(info>40)
print(info[info>40])

Output
Program-24

Series object s11 stores the charity contribution made by each


section. Write a program to display which section made a
contribution more than Rs.5500/- A 6700
B 5600
C 5000
Coding D 5200
Output
Program-25

Consider the given series M1. Write a program in Python Pandas to


create the series
Marks
Term-1 45
Term-2 65
Term-3 24
Term-4 89
Coding
Program-26

Consider two objects x and y . X is a list where as y is a series. Both


have values 20,40,90,110. What will be the output of the following
two statements considering that the above objects have been
created already?
a) print(x*2) b) print(y*2)

Coding Output
Program-27

Consider the below given two code fragments. Will they produce the
same output? Why/Why not?
a) fst=[9,10,11]
ob1=pd.Series(data=fst*2)
print(ob1)
b) fst=pd.Series(data=[9,10,11])
ob2=pd.Series(data=fst*2)
print(ob2)
Coding
Program-28

What will be the output of the following program?


import pandas as pd
fst=[9,10,11]
scd=pd.Series(fst)
ob1=pd.Series(data=fst*2)
ob2=pd.Series(data=scd*2)
print(“ob1”)
print(ob1)
print(“ob2”)
print(ob2)
Coding Output
Program-29

What will be the output of the following program?


import pandas as pd
import numpy as np
data=np.array([‘a1’,’b1’,’c1’,’d1’,’e1’,’f1’])
S=pd.Series(data)
print(“I”)
print(s[:3])
print(“II”)
print(s[-3:])
Coding

Output
Program-30

What will be the output of the following code?


data=np.array([‘a1’,’b1’,’c1’,’d1’,’e1’])
S=pd.Series(data, index=[1001,1002,1003,1004,1005])
print(s[1002,1003,1004])
Coding

Output
Coding

Output
Program-31

Given are two objects, a list objects namely lst1 and a series object
namely ser1, both are having similar values i.e. 2,4,6,8. Find out the
output produced by following statements:
a) print(lst*2) b) print(ser1*2)

Coding Output
Program-32

Given a series that shows the area of some states in km2. Write code
to find out the biggest and smallest three areas from the given
series. given series has been created like this.
Ser1=pd.Series([34567, 890, 450, 67892, 34677, 78902, 25611,
678291,637632, 25723, 2367, 11789, 345, 256517])
Coding
Output
Program-33

From the Ser1 of areas (given earlier that stores areas of states in
km2) , find out the areas that are more than 50000 km2
Ser1=pd.Series([34567,890,450,67892,34677,78902,25611,678291,6
37632,25723,2367,11789,345,256517])

Coding
Output
Program-34

Write a program to sort the values of series object s1 in ascending


order of its values and store it into series object s2.

Coding Output
Program-35 Write a program to sort the values of series object s1 in
descending order of its indexes and store it into series
object s3.

Coding Output
Program-36 Given a series object s4. Write a program to change the
values at its 2nd row(index1) and 3rd row to 8000.
Coding

Output
Program-37

Given a series object s5. Write a program to calculate the cubes of


the series values.
Output
Coding
Program-38

Given a series object s5. Write a program to store the squares of the
series values in the object s6. Display s6’s values which are >15

Output
Coding

You might also like