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

Class 12 IP DataFrame 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)
85 views8 pages

Class 12 IP DataFrame 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

​ ​ DELHI PUBLIC SCHOOL, PALI

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

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

Q1. Write a program to create dataframe “DF” from “[Link]”


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 = [Link](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 = [Link]([35, 40, 71, 25])
B = [Link]([27, 34, 56, 73])
C = [11, 22, 33, 44]
DF = [Link]([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 = [Link](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 = [Link](L1)
print(DF)
Q24. There are 7 rows in a dataframe “DF”. How many rows will be displayed
by the following statement?
[Link](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 : [Link]( )
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 = [Link]([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 : [Link][“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([Link] 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 = [Link](“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([Link][“Two”])
b. print([Link][ : , “Ename”])
c. print(DF[“Ename”])
d. print([Link][“One”,“Two”])
e. print([Link][[“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([Link][“Maths”] > 90)
b. print([Link][ : , “Arnab”] > 90)
c. print([Link][‘Maths’ : ‘Science’])
d. print([Link][‘Hindi’ : ‘English’])
e. Following two statements will produce the same result ?(Yes/No)
1.​ print(DF)
2.​ print([Link][‘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([Link])
o. Write the output of : print([Link])
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([Link])
r. Write the output of : print([Link])
s. Write the output of the following statement
DF1 = [Link]['Maths' : 'Science' , ['Arnab' , 'Samridhi']]
print(DF1 * 2)
t. Write the output of the following statement
DF1 = ([Link]['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 = [Link]['English' : 'Hindi']
DF2 = [Link]['English' : 'Hindi']
print(DF1 + DF2)
y. Write the output of the following :
DF1 = [Link]['English' : 'Hindi']
DF2 = [Link]['Maths' : 'Science']
DF1 = [Link](DF2)
print(DF1)
z. Write the output of the following :
DF1 = [Link]['English' : 'Hindi']
DF2 = [Link]['Maths' : 'Science']
DF1 = [Link](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([Link][0 : 1])
print([Link]["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.
[Link]("Amit")
print(DF)
h. Write a program to write dataframe “DF” to “[Link]”
Q54. What is DataFrame?

Common questions

Powered by AI

The `loc` attribute in Pandas is used for label-based indexing, which means selecting rows and columns by their label instead of their integer location. Direct column indexing, such as `DataFrame['column_name']`, retrieves a column directly as a Series. `loc` can be useful when you need to access a subset of the DataFrame using labels, allowing for more than one label or conditional logic. Direct indexing is straightforward for accessing a single column, making it ideal in simpler scenarios .

The `.drop()` method in Pandas allows you to delete a row or column. The crucial parameter is `axis`, where `axis=0` specifies that a row is being removed, and `axis=1` specifies that a column is being removed. Additionally, the `labels` parameter is used to specify the index or column label to be dropped .

The `del` statement and the `drop()` function both remove columns from a DataFrame, but they function differently. `del` is used to irreversibly delete a column in place by specifying the column name with dot notation, such as `del DataFrame['column_name']`. In contrast, `drop()` returns a modified DataFrame with the specified column removed and has an `axis` parameter which must be set to 1 for column deletion. Unlike `del`, `drop()` can target multiple columns and can be used without affecting the original DataFrame when `inplace=False` .

You can create a DataFrame in Python from a dictionary of lists using the Pandas library. First, import Pandas as pd, then use `pd.DataFrame(<dictionary>)` to create the DataFrame. For accessing structural information, you can use attributes like `.shape` for dimensions, `.columns` for column labels, `.index` for row labels, and `.dtypes` for data types .

A Pandas Series is a one-dimensional array-like object containing a sequence of values with an associated array of data labels (index). A DataFrame is a two-dimensional table of data with rows and columns. Series can be thought of as a single column of a DataFrame, while a DataFrame contains multiple Series. DataFrames can handle data in a tabular format with multiple columns and rows, whereas Series is suitable for storing a single column or row of data .

When adding a row or column with insufficient data values compared to the existing structure, Pandas will generate an error indicating a mismatch in expected and provided data size. For a row, this results in a `ValueError` for unequal numbers of columns. For a column, it will either cause a similar mismatch error or fill the missing values with `NaN` if the length is less than the number of existing rows .

To insert a new column at a specific position, you can use the `insert()` method of the DataFrame object, e.g., `DataFrame.insert(loc=position, column='column_name', value=new_values)`. The `loc` parameter specifies the index position where the column should be inserted, making it easy to tailor DataFrame layout. It is crucial to ensure any sequential operations relying on column order are updated to reflect the new layout, as inserting columns affects the index positions of all subsequent columns .

Pandas offers the `.T` attribute and the `transpose()` method for transposing a DataFrame, effectively swapping rows and columns. This transpose operation is beneficial in scenarios where the row-oriented operations need to be rerun on columns, such as when preparing data to fit certain analysis models, or when evaluating statistics across rows that make logical sense when framed as columnar data. It is especially useful in matrix operations or when adjusting the data format for visualization or export purposes .

To update a DataFrame's index values, use the `.set_index()` or `.rename()` method. With `.set_index()`, you can replace the current index with another column's data, effectively promoting that column's values to the index position. `.rename()` allows for changing specific index values by passing a dictionary of {old: new} pairs. Care should be taken to ensure new index values are unique unless explicitly allowed by the index parameters; otherwise, it can lead to unexpected results or errors .

The method `DataFrame.empty` is used to check if a DataFrame is empty. When called, it returns `True` if the DataFrame has no items, which means it possesses zero rows and columns, and `False` otherwise .

You might also like