0% found this document useful (0 votes)
878 views6 pages

Class 12 IP DataFrame Worksheet

Uploaded by

rihanais12345
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)
878 views6 pages

Class 12 IP DataFrame Worksheet

Uploaded by

rihanais12345
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
  • Exercise Set 1: Initial DataFrame Tasks

WORKSHEET :PANDAS DATAFRAME

CLASS :XII SUBJECT:IP


1. Consider the following Data Frame df and answer questions:

A B C
DEPT CS PROD MEDICAL
EMPNO 101 102 103
ENAME ABC PQR LMN
SALARY 200000 100000 20000

i. Write code to delete column B

ii. Write the output of the below code

print([Link](2))
iii. Write code to delete row salary

iv. Change the value of column A to 100


v. .Change the value of DEPT of B to MECH
vi. Display DEPT and SALARY of column A and B
vii. Write code to rename column ‘A’ to ‘D’ which
will not effect original dataframe
viii. Write code to add a column E with values [CS,
104,XYZ, 300000]
ix. Write code to add a row COMM with values
[3000,4000,5000]
x. Write code to rename DEPT to DEPARTMENT which
will effect the original dataframe
xi. Write code to display DEPT in A
i. print(df.A[‘DEPT’])
ii. print(df[‘A’,’DEPT’])
iii. print([Link][1:2,1:2])

iv. print([Link][3,2])
xii. Write the output of the statement print(len(df))

i. 3
ii. 4
iii. (4,3)
iv. (3,4)

Answers :=

i. del df['A']

ii. A B C
ENAME ABC PQR LMN
SALARY 200000 100000 20000
iii. df=[Link](['SALARY'],axis=0)

iv. df['A']=100
v. df.B['DEPT']='MECH'

vi. print([Link][['DEPT','SALARY'],["A","B"]])

vii. [Link](columns={"A":"D"},inplace=False)
viii. df['E']=["CS",104,"XYZ",300000]
ix. [Link]['COMM']=[3000,4000,5000]
x. [Link](index={"DEPT":"DEPARTMENT"},inplace=True)

xi. print(df.A[‘DEPT’])

xii. 4

[Link] the following Data Frame df and answer questions


ACC BST ECO IP
S1 90 91 92 93
S2 94 95 96 97
S3 98 99 100 100
S4 91 92 93 94
Create a new column total TOT by adding marks
i. Find the highest marks scored by student s1
ii. Find the lowest marks scored by student s1
iii. Find the highest marks in ACC
iv.
Find the lowest marks in IP

Answers:=
i. df['TOT']=df['ACC']+df['BST']+df['ECO']+df['IP']
ii. print(max([Link]['S1',:]))
iii. print(min([Link]['S1',:]))
iv. print(max(df['ACC']))
v. print(min(df['IP']))
[Link] the following Data Frame df and answer questions

delhi mumbai kolkatta chennai

hospitals 200 300 100 50

population 10 20 30 40

schools 250 350 400 200

i. Display details of city delhi and chennai


ii. Display hospitals in delhi
iii. Display shape of dataframe
iv. Change the population in kolkatta as 50
v. Rename the column population as “pop”
Answers:=
i. print(df[['delhi','chennai']])
ii. print([Link]['hospitals'])
iii. print([Link])
iv. [Link]['population']=50
[Link](index={"population":"pop"},inplace=True)

[Link] the following Data Frame df and answer questions

i. Display the name of city whose


population >=20 range of 12 to
20
ii. Write command to set all vales of df as 0
iii. Display the df with rows in the reverse order
iv. Display the df with only columns in the reverse order
v. Display the df with rows & columns in the reverse
order

Answers:-
i. print(df[[Link]>=20])
ii. df[:]=0
iii. print([Link][::-1)
iv. print([Link][:,::-1])
v. print([Link][::-1,::-1])
2. Consider the following Data Frame df and & answer questions
Write the ouput of the following
i. print(len(df))
ii. print([Link]())
iii. print([Link](1))
iv. print(min([Link]['SALARY']))
v. print(max([Link]['ENAME']))
Answers:
i. 4
ii. A 4
B 4
C 4
dtype: int64
iii. DEPT 3
EMPNO 3
ENAME 3
SALARY 3
dtype: int64
iv. 20000
v. PQR
QUESTIONS ON DATAFRAME
1. What are the purpose of following
statements- [Link]
2. [Link][ : , :-5]
3. df[2:8]
4. df[ :]
5. [Link][ : -4 , : ]
Ans:
1. It displays the names of columns of the Dataframe.
2. It will display all columns except the last 5 columns.
3. It displays all columns with row index 2 to 7.
4. It will display entire dataframe with all rows and columns.
5. It will display all rows except the last 4 four rows
2. What will be the output of [Link][3:7,3:6]?
Ans:
It will display the rows with index 3 to 6 and columns with index 3 to 5 in
a dataframe ‘df’.
[Link] a python program to create a data frame with headings
(CS and IP) from the list given below-
[[79,92][86,96],[85,91],[80,99]]
Ans:
l=[[10,20],[20,30],[30,40]]
df=[Link](l,columns=['CS','
IP'])
print(df)
[Link] python statement to delete the 3rd and 5th rows
from
Dataframe df.

df1=[Link](index=[2,4],axis=0)

OR

df1=[Link]([2,4])

WORKSHEET :PANDAS DATAFRAME
CLASS :XII  
SUBJECT:IP
1. Consider the following Data Frame df and answer questions:
A
B
C
DEPT
xii. Write the output of the statement print(len(df))
i.
3
ii.
4
iii.
(4,3)
iv. (3,4) 
Answers :=
i. del df['A']
ii.
    
A
B
Create a new column total TOT by adding marks
i.
Find the highest marks scored by student s1
ii.
Find the lowest marks scored
i.
print(df[['delhi','chennai']])
ii.
print(df.delhi['hospitals'])
iii.
print(df.shape)
iv.
df.kolkatta['population']=50
Write the ouput of the following
i.
print(len(df))
ii.
print(df.count())
iii.
print(df.count(1))
iv.
print(min(df.loc['SALARY
2.
It will display all columns except the last 5 columns.
3.
It displays all columns with row index 2 to 7.
4.
It will displa

You might also like