0% found this document useful (0 votes)
127 views3 pages

IP Assignment 1 XII

Uploaded by

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

IP Assignment 1 XII

Uploaded by

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

Assignment 1

Section I
1 To get a number representing number of axes in a DataFrame, _______ attribute may be used.
a) Size b) Shape c) Values d) ndim

2 To display the 3rd,4th and 5th columns from the 6th to 9th rows of a DataFrame DF, you can write____.
a)DF.loc[6:9, 3:5] b)DF.loc[6:10, 3:6]
c)DF.iloc[6:10, 3:6] d)DF.iloc[6:9, 3:5]
3 Consider a Series object vls, created using following statement:
vls = pd.Series([11, 23, 31, 61, 87, 93], index = [‘a’,’b’,’c’,’d’,’e’,’f’])
Based on this series object, write statements to do the following:
i) Retrieve and print the first three elements.
ii) Retrieve and print elements, starting from index ‘b’ and ‘c’.

4 Write a program to create a DataFrame to store Weight, Age and Name of 3 people. Print the
DataFrame and its transpose.
5 Trying to extract the first five rows of DataFrame DF, Nia has given code as:
DF.loc[0:5]
But it is returning 6 rows. Why? Suggest the solution.

6 What is Pandas library of Python? What is its significance?

7 Differentiate between Series and DataFrame.

8 Write the correct output of the execution of the following pandas code:
import pandas as pd
df=pd.DataFrame({“A”:[“P01”,”P02”,”P03”], “B”:[“PEN”,”PENCIL”,”ERASER”]})
df=df.rename(columns={“A”:”PID”,”B”:”PNAME”})
df=df.rename(index={0:’A’,1:’B’,2:’C’})
print(df)
9 Create a DataFrame named “Booking” with following data –
Tcode Name Ticket Amount
T0001 Anuj Mehita 5 1355
T0002 Sandeep Oza 2 1169
T0003 Manoj Sharma 6 1958

SECTION II
10 A DataFrame namely Result stores the details of students’ marks in different subjects for a class of 50
students. The records are arranged in the descending order of total marks obtained by a student.
Eng IP Math
10 77 78 78
11 82 85 67
12 55 66 66
13 66 76 73
14 78 60 44
i) Write a statement to print the five least scoring students’ details. (Choose the correct option)
a) Result.last() b) Result.tail()
c) Result.last(5) d) Result.tail(5)
ii) Write the output for the following:
a) Result.at [12, Math]
b) Result.iat [3, 1]
iii) Write a statement to print the three highest scoring students. (Choose the correct option)
a)Result.top() b)Result.top(3)
c)Result.head() d)Result.head(n=3)
iv) Write a statement to display the marks scored by a student with roll number 22, in the subject ‘Math’.
a)Result.loc[22,’Math’] b)Result.at[22,’Math’]
c)Result.iat[22,’Math’] d)Result.iloc[22,’Math’]

11 Write Python code to create a DataFrame named “Furniture” with following data-

Item Material Color Price


Sofa Wooden Maroon 25000
Dining Table Plywood Yellow 20000
Chair Plastic Red 1500
Sofa Stainless Steel Silver 55000
Chair Wooden Light Blue 2500
Dining Table Aluminum Golden 65000

a) Display details of only chair.


b) Display details of furniture where price is more than 25000.
c) Write a small python code to drop a row from DataFrame furniture labeled as 0.
d) Explain what the following statements are doing? df is the name of a DataFrame.

(i) df.iloc[:5, ] (ii) df.iloc[1:5]


(iii) df.iloc[5, 0] (iv) df.iloc[1:5, 0]
(v) df.iloc[1:5, :5] (vi) df.iloc[2:7, 1:3]

12 Write a program to create a DataFrame from a 2D list . Specify own index labels. Assume that pandas
library has been imported as pd.

13 Given a DataFrame namely aid that stores the aid by NGOs for different states: 2

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

Write statements to display the value for


(i) Books and Uniform only (ii) Shoes only

Assume that Pandas library has been imported as pd and DataFrame aid is already created.

14 A Series object trdata consists of around 2500 rows of data. Write a program to print the following 2
details:
(I) First 100 rows of data.
(ii) Last 5rows of data.
Assume that Pandas library has been imported as pd.

You might also like