List of Programs For Practical File

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

List of programs for practical file based on Series ,Dataframes and CSV Files.

Program on Pandas

Q.1) 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.

Q.2) Total number of medals to be won is 200 in the Inter University games held every
alternate year. Write code to create a Series object that stores these medals for games to
be held in the decade 2020 - 2029.

Q.3) Sequences 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 a Series object that stores the contribution amount as the values and
the section names as the indexes with data type as float32.

Q.4) Consider the Series object created in previous program, write a program to print the
attributes of the series object in a report form as shown below:
Attribute Name Series Object
Data Type
Shape
No of bytes
No of dimensions
Item Size
Has NaNs?
Empty?

Q.5) Consider a Series object that stores the number of students in each section of class 12 (as
shown below)
A 39
B 41
C 42
D 44
First two sections have been given a task of selling tickets @ 100/- per ticket as part of a
social experiment. Write code to display how much they have collected.
Q.6) Consider the Series object that stores the contribution of each section, as shown below:
A 6700
B 5600
C 5000
D 5200
a) Write a program to display which sections made a contribution more than Rs 5500.
` b) Write code to modify the amount of section 'A' as 7600 and for sections 'C' and 'D' as
7000. Print the changed object.

Q.7) Number of students in classes 11 and 12 in three streams ('Science', 'Commerce' and
'Humanities') are stored in two Series objects c11 and c12. Write code to find total
number of students in classes 11 and 12, stream wise.

Q.8) Object1 Population stores the details of population in 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.
Use indexes in both the objects as ['Delhi', 'Mumbai', 'Kolkata', 'Chennai'].
Display population, average income and income per capita with proper headings.

Q.9) Given a Series object that stores 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, 256711, 768291, 637632,
25723, 2367, 11789, 345, 256517])
Also find out the areas that are more than 5000 km2.

Q.10) Given a dictionary that stores the section names list as value for 'Section' key and
contribution amounts list as value for 'Contri' key:
dict1 = {'Section' : ['A', 'B', 'C', 'D'], 'Contri' : [6700, 5600, 5000, 5200]}
Write code to create and display the data frame using above dictionary.

Q.11) Create and display a DataFrame from a 2D dictionary, Sales, which stores the quarter
wise sales as inner dictionary for two years.

Q.12) Write a program to create a dataframe from a list containing dictionaries of the Sales
performance of four zonal offices. Zone names should be the row labels. Each dictionary
contains target and sales amount.

Q.13) Consider two Series objects staff and salaries that store the number of people in various
office branches and salaries distributed in these branches, respectively.
Write a program to create another Series object that stores average salary per branch and
then create a DataFrame object from these Series objects.
Q.14) Create a DataFrame namely aid that stores the aid by NGOs for different states:
Toys Books Uniform Shoes
Andhra 7916 6189 610 8810
Odisha 8508 8208 508 6798
M.P. 7226 6149 611 9611
U.P. 7617 6157 457 6457
a) Write a code to display the aid for
i) Books and Uniform only
ii) Shoes only
b) Write a code to display the aid for staes 'Andhra' and 'Odisha' for Books and Uniform
only.
c) Write code to add a new column stationary.
d) Write code to add a new row for 'Rajasthan'. Assume the values yourself.
e) Write code to remove row 'M.P.' and column 'Uniform'.

Q.15) Create a dataframe using dictionary to store the quarterly sales for three years.
i) Write code to extract data from dataframe row wise.
ii) Write code to extract data from dataframe column wise.

Q.16) Write a program that reads from a csv file (marks.csv stored in data folder of C: drive
having data as name of students and marks in three subjects) in a dataframe. Then the
program should add a column 'Total' storing total marks of three subjects and another
column storing average marks. Print the dataframe after adding these columns.
Also illustrate the use of various attributes of read_csv method.
Write code to transfer the data from dataframe to csv file also.

You might also like