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

Chapter 2 Pandas Python I Extra Questions

The document is a question paper for Class XII Informatics Practices at Delhi Public School, Pali for the academic year 2025-2026. It contains various programming questions related to creating and manipulating dataframes using the pandas library in Python. The questions cover topics such as dataframe creation, indexing, modifying values, and handling errors.

Uploaded by

priish1884
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)
82 views8 pages

Chapter 2 Pandas Python I Extra Questions

The document is a question paper for Class XII Informatics Practices at Delhi Public School, Pali for the academic year 2025-2026. It contains various programming questions related to creating and manipulating dataframes using the pandas library in Python. The questions cover topics such as dataframe creation, indexing, modifying values, and handling errors.

Uploaded by

priish1884
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

​ ​ DELHI PUBLIC SCHOOL, PALI

2025-2026
SUBJECT- INFORMATICS PRACTICES (065) ​
CLASS – XII

Name of Student ………………………………​

Q1. Write a program to create dataframe “DF” from “data.csv”


Q2. Complete the following code to get the Output given below:
import pandas as pd
L1 = {"Name" : ["Aman", "Ankit", "Sunita"], "Marks" : [45, 56, 67]}
DF = pd.DataFrame(L1, columns = [______________________],
index = [1, 2, 3])
print(DF)
Q3. _______ method in Pandas is used to change/modify the index of rows
and columns of a Dataframe.
Q4. Write two differences between Series and DataFrame.
Q5. Give an example of creating dataframe from two series.
Q6. Which data types can be used to create DataFrame?
Q7. Which library is to be imported to create dataframe from Numpy
ndarrays ?
Q8. Which method is used to create DataFrame in Python?
Q9. Give an example to create dataframe from a single ndarray.
Q10. Give an example to create dataframe from two ndarray.
Q11. Write the output of the following code:
import numpy as np
import pandas as pd
A = np.array([35, 40, 71, 25])
B = np.array([27, 34, 56, 73])
C = [11, 22, 33, 44]
DF = pd.DataFrame([A, B, C])
print(DF)
Q12. Write the code in python to create dataframe from given list.
L1 = [“Anil”, “Ruby”, “Raman”, “Suman”]
L2 = [35, 56, 48, 85]
Q13. Write two methods of creating the following dataframe “DF”.
​ Name ​ Class
0​ Anju​ 7
1​ Suman​ 11
Q14. Name the function which is used to display first n rows in the
DataFrame.
Q15. When we try to add a row with lesser values than the number of
columns in the DataFrame, it results in a ____________ error.
Q16. Which attribute of DataFrame is used to give user defined
column name
Q17. Complete the following code to get the Output given below:
import pandas as ________________
L1 = [["Aman", 45], ["Ankit", 56], ["__________", 67]]
DF = pd.______________(L1, ______________=["Name", "Marks"],
index=[__________])
print(DF)
Q18. Write code to create empty DataFrame named ‘DF1’.
Q19. Consider the code given below and answer the following questions:
Ld = [{'a' : 10, 'b' : 20}, {'a' : 5, 'b' : 10, 'c' : 20}]
DF = pd.DataFrame(Ld)
print(DF)
a. How many rows will be there in dataframe “DF”?
b. How many columns will be there in dataframe “DF”?
c. How many Nans will be there in dataframe “DF”?
d. Write the missing import statement in the above code.
e. How many dictionaries are used in the above code?
Q20. Create the following dataframe using List of Dictionaries.
​ A​ B​ C
0​ 1​ 2​ 3
1​ 5​ 6​ 8

Q21. Write five attributes of DataFrame.


Q22. Which attribute of dataframe is used for the following.
1.​ To display row labels.
2.​ To display column labels.
3.​ To display data type of each column in the DataFrame.
4.​ To display all the values in the DataFrame.
5.​ To display number of rows and columns in a tuple.
6.​ To display total number of values in the dataframe.
7.​ To transpose the dataframe.
8.​ To returns the value True if DataFrame is empty and False otherwise
Q23. Aman store some data in the form of nested list. Later on, he created
dataframe “DF” from the list given below by writing the following code. How
many columns will be there in “DF”
L1 = [[“Aman”, “Cricket”, “7th”], [“Ankit”, “Hockey”, “11th”], [“Sunita”,
“Basketball”, “9th”]]
import pandas as pd
L1 = [["Aman", "Cricket", "7th"], ["Ankit", "Hockey", "11th"], ["Sunita",
"Basketball", "9th"]]
DF = pd.DataFrame(L1)
print(DF)
Q24. There are 7 rows in a dataframe “DF”. How many rows will be displayed
by the following statement?
DF.head(10)
Q25. Write a statement to display last 7 rows from dataframe “DF”.
Q26. Write a statement to display first 7 rows from dataframe “DF”.
Q27. What is the default value of ‘n’ in tail(n) function?
Q28. Write a statement in python to add a new column “Marks” with values
(23, 34, 45, 12) in a dataframe “DF”
Q29. Consider the following dataframe “DF”
​ A​ B​ C
0​ 1​ 2​ 3
1​ 5​ 6​ 8
a) Write a statement to change values of column “C”. New values are (4, 9)
b) Write a statement to change all the values of column “B” to 0
c) Write a statement to add a new row with value (7, 8, 9)
d) Write a statement that will return the result (2,3)
e) Write the output of the statement : DF.size( )
Q30. Fill in the blanks
import pandas as pd
import numpy as np
Name = ______________.array([‘Anil’, ’Sumit’, ’Akhil’, 'Ananya'])
__________ = ________.DataFrame( )
print(DF)
Q31. Fill in the blank to produce the Output.
import pandas as pd
L1 = ["Anil", "Ruby", "Raman", "Suman"]
L2 = [35, 56, 48, 85]
DF = pd.DataFrame([L1, L2], ___________________________________ )
print(DF)
Q32. Consider the above dataframe “DF” (Q. 31) and write the code to add a
new column “Roll no” with values (21, 22)
Q33. Consider the above dataframe “DF” (Q. 31) and write the code to
update the value of column “Roll No”. New values are (23, 27)
Q34. Consider the above dataframe “DF” (Q. 31) and write the code to
change the values of column “Class” to “12”
Q35. Consider the above dataframe “DF” (Q. 31) and write the code to
change the index values of both rows. Index value 0 and 1 should be replaced
by “First” and “Second” respectively.
Q36. Which function/method is used to add a new row in dataframe?
Q37. Aman wants to add a new row with values (“Suman”, 9, 11) at the end
of the dataframe “df”. He does not know the total number of rows available in
dataframe. As a friend of Aman, help him to write the code.
Q38. Which of the following code will change the value of entire row to “0” in
dataframe “DF”.
Code A : DF.loc[“preeti”] = 0
Code B : DF[“Preeti”] = 0
Q39. Which attribute of DataFrame is used to give user defined index value?

Q40. When we try to add a column with lesser values than the number of
rows in the DataFrame, it results in a ____________ error.
Q41. We can use the ___________________ method to delete rows
and columns from a DataFrame.
Q42. Write the code to delete the row with label ‘Book’ from dataframe “DF”
Q43. Which parameter of drop( ) function is used to specify the row or
column to be delete?
Q44. Write the code to delete the column with label ‘Marks’ from dataframe
“DF”.
Q45. Write the code to delete the columns with label ‘Marks’, ‘Class’ and
‘Rollno’ from dataframe “DF”.
Q46. a) Raman wants to create a pandas dataframe from the data given
below. He wants to give column name as “Emp no” and “Ename”. Help him to
write the code.
L1 = [[1, “Anil”], [2, “Sunil”], [3, “Suman”]]
Q46. b) Raman wants to display the column “Emp no” from dataframe “DF”.
He writes the following code which is not working. Help him to correct the
error.
print(DF.Emp no)
Q46. c) Raman’s friend Shreya asks him to add a new column “Salary” in
dataframe “DF” with values (10000, 20000, 25000). Help him to write the
code.
Q46. d) What type of error is returned by the following statement written by
Raman?
DF = DF.drop(“Sal”, axis = 1)
Q46. e) Raman wants to change the column label “Salary” to “Salaries”. Help
him to write the code.
Q46. f) Raman wants to change the row label 0, 1, 2 to “One”, “Two”, “Three”
respectively. Help him to write the code.
Q47. Write two ways of indexing dataframe.
Q48. Consider the pandas dataframe “DF” given below:
Emp no Ename
One 1 Anil
Two 2 Sunil
Three 3 Suman
Write the output of :
a. print(DF.loc[“Two”])
b. print(DF.loc[ : , “Ename”])
c. print(DF[“Ename”])
d. print(DF.loc[“One”,“Two”])
e. print(DF.loc[[“One”,“Two”]])
f. print(DF[“Emp no”,“Ename”])
g. print(DF[[“Emp no”,“ Ename”]])
Q49. Consider the pandas dataframe “DF” given below:
Arnab Ramit Samridhi Riya
Mallika
Maths 90 92 89 81
94
Science 91 81 91 71
95
English 85 86 83 80
90
Hindi 97 96 88 67
99
Write the output of :
a. print(DF.loc[“Maths”] > 90)
b. print(DF.loc[ : , “Arnab”] > 90)
c. print(DF.loc[‘Maths’ : ‘Science’])
d. print(DF.loc[‘Hindi’ : ‘English’])
e. Following two statements will produce the same result ?(Yes/No)
1.​ print(DF)
2.​ print(DF.loc[‘Maths’ : ‘Hindi’])
f. print(DF[[‘Arnab’ , ‘Ramit’ , ‘Riya’]])
g. Write a statement to display marks of “Arnab” and “Ramit” of subjects
“Maths”, “Science” and “English”.
h. Write the statement to display Marks of “Arnab” in “Maths”.
i. Write the statement to display marks of “Riya” in all subjects.
j. Write the statement to display marks of Ramit, Samridhi and Riya of
“English” Subject.
k. Write the output of the following statement:
l. Write a statement to display the first record of pandas dataframe “DF”.
m. Write a statement to display the last three records of pandas dataframe
“DF.
n. Write the output of : print(DF.shape)
o. Write the output of : print(DF.ndim)
p. Write a statement to get the following as output :
Maths Science English Hindi
Arnab 90 91 85 97
Ramit 92 81 86 96
Samridhi 89 91 83 88
Riya 81 71 80 67
Mallika 94 95 90 99
q. Write the output of : print(DF.size)
r. Write the output of : print(DF.empty)
s. Write the output of the following statement
DF1 = DF.loc['Maths' : 'Science' , ['Arnab' , 'Samridhi']]
print(DF1 * 2)
t. Write the output of the following statement
DF1 = (DF.loc['Hindi' : 'Hindi' , 'Riya' : 'Riya'])
print(DF1 % 2)
u. Write the code to find the highest marks in subject “Hindi”
v. Write the code to find the lowest marks in subject “English”
w. Write the output of the statement : print(min(DF))
x. Write the output of the following code:
DF1 = DF.loc['English' : 'Hindi']
DF2 = DF.loc['English' : 'Hindi']
print(DF1 + DF2)
y. Write the output of the following :
DF1 = DF.loc['English' : 'Hindi']
DF2 = DF.loc['Maths' : 'Science']
DF1 = DF1.append(DF2)
print(DF1)
z. Write the output of the following :
DF1 = DF.loc['English' : 'Hindi']
DF2 = DF.loc['Maths' : 'Science']
DF1 = DF1.append(DF2, sort = "True")
print(DF1)
Q50. Which function in pandas dataframe is used to insert a new column at
specific position?
Q51. Name two functions/statement which are used to delete column from
pandas dataframe?
Q52. Write two differences between del statement and drop() function of
pandas dataframe.
Q53. Consider the pandas dataframe “DF” given below:
Arnab Ramit Samridhi Riya
Mallika
Maths 90 92 89 81
94
Science 91 81 91 71
95
English 85 86 83 80
90
Hindi 97 96 88 67
99
a. Write the code to insert column “Amit” with values (90, 92, 95, 89) at
position 5 (after Mallika)
b. Write the code to insert column “Amit” with values (90, 92, 95, 89) at
position 2.
c. Write the code to delete column “Riya” from dataframe “DF”
d. Write the code to delete columns “Ramit” and “Riya” from dataframe “DF”
e. Following two statements will give same or different result.
print(DF.iloc[0 : 1])
print(DF.loc["Maths" : "Maths"])
f. Write the statement to display marks of “Amit” in “Maths”.
g. Aman has written the following command to delete the column “Amit” from
dataframe “DF”. Output is not coming. Help him to correct the code.
DF.drop("Amit")
print(DF)
h. Write a program to write dataframe “DF” to “data.csv”
Q54. What is DataFrame?

You might also like