CBSE Class 12
Informatics Practices
02 Data Handling using Pandas - I
50
Total
0
Attempted
0
Correct
0
Wrong
00:00:00
Q-1
Which Python library is primarily used for data analysis and handling tabular data?
Easy
Python Libraries
A
NumPy
B
Matplotlib
C
Pandas
D
Seaborn
Answer: Pandas
Explanation: Pandas is specifically designed for data analysis and handling structured data.
Q-2
Which data structure in Pandas is one-dimensional?
Easy
Pandas Series
A
DataFrame
B
Series
C
ndarray
D
Index
Answer: Series
Explanation: A Pandas Series is a one-dimensional labeled array.
Q-3
How many elements are present in the following Series?
Easy
Pandas Series
Sample Data
s = [10, 20, 30, 40]
Reference Code
import pandas as pd
s = pd.Series([10, 20, 30, 40])
A
3
B
4
C
5
D
Error
Answer: 4
Explanation: The Series is created from a list containing four values.
Q-4
Which attribute is used to display the values of a Pandas Series?
Easy
Pandas Series
A
index
B
values
C
shape
D
dtype
Answer: values
Explanation: The values attribute returns the data stored in the Series.
Q-5
Which object represents rows and columns in Pandas?
Easy
Pandas DataFrame
A
Series
B
Index
C
DataFrame
D
ndarray
Answer: DataFrame
Explanation: A DataFrame is a two-dimensional structure with rows and columns.
Q-6
How many columns are present in the given DataFrame?
Easy
Pandas DataFrame
Sample Data
| Name | Age | Marks |
|---|---|---|
| Anu | 16 | 85 |
| Ravi | 17 | 78 |
Reference Code
import pandas as pd
df = pd.DataFrame({
'Name': ['Anu', 'Ravi'],
'Age': [16, 17],
'Marks': [85, 78]
})
A
1
B
2
C
3
D
4
Answer: 3
Explanation: The DataFrame has three columns: Name, Age, and Marks.
Q-7
Which function is used to read data from a CSV file into a DataFrame?
Easy
CSV Import Export
A
read_csv()
B
load_csv()
C
import_csv()
D
open_csv()
Answer: read_csv()
Explanation: The read_csv() function is used to read CSV files into Pandas DataFrames.
Q-8
Which function is used to write a DataFrame to a CSV file?
Easy
CSV Import Export
A
to_csv()
B
write_csv()
C
save_csv()
D
export_csv()
Answer: to_csv()
Explanation: The to_csv() function writes a DataFrame to a CSV file.
Q-9
Which library provides the ndarray data structure?
Easy
Pandas vs NumPy
A
Pandas
B
NumPy
C
Matplotlib
D
SciPy
Answer: NumPy
Explanation: NumPy provides the ndarray data structure for numerical computing.
Q-10
Which statement correctly distinguishes a Pandas Series from a NumPy ndarray?
Easy
Pandas vs NumPy
A
Series supports labels while ndarray does not
B
ndarray supports labels while Series does not
C
Series is always two-dimensional
D
ndarray cannot store numeric data
Answer: Series supports labels while ndarray does not
Explanation: A Pandas Series has index labels, whereas a NumPy ndarray does not support labels.
Q-11
What will be the index values of the Series created by the code?
Medium
Pandas Series
Sample Data
Data values: [100, 200, 300]
Reference Code
import pandas as pd
s = pd.Series([100, 200, 300])
A
[1, 2, 3]
B
[0, 1, 2]
C
[100, 200, 300]
D
Index is undefined
Answer: [0, 1, 2]
Explanation: By default, Pandas assigns integer index values starting from 0.
Q-12
What will be the output of the following statement?
Medium
Pandas Series
Sample Data
s = [10, 20, 30]
Reference Code
import pandas as pd
s = pd.Series([10, 20, 30])
print(s[1])
A
10
B
20
C
30
D
IndexError
Answer: 20
Explanation: Index position 1 refers to the second element of the Series, which is 20.
Q-13
How many rows and columns does the DataFrame have?
Medium
Pandas DataFrame
Sample Data
| Name | Maths | Science |
|---|---|---|
| Anu | 80 | 85 |
| Ravi | 75 | 78 |
| Meena | 90 | 88 |
Reference Code
import pandas as pd
df = pd.DataFrame({
'Name': ['Anu', 'Ravi', 'Meena'],
'Maths': [80, 75, 90],
'Science': [85, 78, 88]
})
A
2 rows and 3 columns
B
3 rows and 2 columns
C
3 rows and 3 columns
D
2 rows and 2 columns
Answer: 3 rows and 3 columns
Explanation: The DataFrame has 3 rows (students) and 3 columns (Name, Maths, Science).
Q-14
Which column will be returned by the following statement?
Medium
Pandas DataFrame
Sample Data
DataFrame with columns: Name, Age, Marks
Reference Code
print(df['Marks'])
A
Only Marks column as Series
B
Entire DataFrame
C
Only Marks column as DataFrame
D
Index values only
Answer: Only Marks column as Series
Explanation: Accessing a single column using df['column'] returns a Series.
Q-15
Which function is used to display the first five rows of a DataFrame?
Medium
Pandas DataFrame
A
head()
B
top()
C
first()
D
start()
Answer: head()
Explanation: The head() function displays the first five rows by default.
Q-16
What will be the shape of the DataFrame?
Medium
Pandas DataFrame
Sample Data
| A | B |
|---|---|
| 1 | 4 |
| 2 | 5 |
| 3 | 6 |
| 4 | 7 |
Reference Code
import pandas as pd
df = pd.DataFrame({'A':[1,2,3,4],'B':[4,5,6,7]})
print(df.shape)
A
(2, 4)
B
(4, 2)
C
(3, 2)
D
(2, 3)
Answer: (4, 2)
Explanation: The DataFrame has 4 rows and 2 columns, so shape is (4, 2).
Q-17
Which parameter is used to prevent the index from being written to a CSV file?
Medium
CSV Import Export
A
index=False
B
header=False
C
columns=False
D
axis=False
Answer: index=False
Explanation: Setting index=False prevents the index from being written to the CSV file.
Q-18
What type of object is returned by read_csv()?
Medium
CSV Import Export
A
Series
B
DataFrame
C
ndarray
D
List
Answer: DataFrame
Explanation: The read_csv() function returns a Pandas DataFrame.
Q-19
Which statement about Pandas Series and NumPy ndarray is correct?
Medium
Pandas vs NumPy
A
Both support labeled indexing
B
Only Series supports labeled indexing
C
Only ndarray supports labeled indexing
D
Neither supports indexing
Answer: Only Series supports labeled indexing
Explanation: Pandas Series supports labeled indexing, while NumPy ndarray does not.
Q-20
Which attribute is used to check the data type of elements stored in a Series?
Medium
Pandas Series
A
type
B
dtype
C
dtypes
D
datetype
Answer: dtype
Explanation: The dtype attribute shows the data type of elements in a Series.
Q-21
What will be the output of the following code?
Hard
Pandas Series
Sample Data
Series values: [5, 10, 15]
Reference Code
import pandas as pd
s = pd.Series([5, 10, 15], index=['a', 'b', 'c'])
print(s['b'])
A
5
B
10
C
15
D
KeyError
Answer: 10
Explanation: Label-based indexing is used. Index 'b' corresponds to value 10.
Q-22
What will be returned by the following statement?
Hard
Pandas DataFrame
Sample Data
DataFrame with columns: Name, Marks
Reference Code
print(type(df['Marks']))
A
<class 'pandas.core.series.Series'>
B
<class 'pandas.core.frame.DataFrame'>
C
<class 'numpy.ndarray'>
D
<class 'list'>
Answer: <class 'pandas.core.series.Series'>
Explanation: Accessing a single column using df['Marks'] returns a Pandas Series.
Q-23
What will be the shape of the DataFrame after execution?
Hard
Pandas DataFrame
Sample Data
| A | B | C |
|---|---|---|
| 1 | 4 | 7 |
| 2 | 5 | 8 |
Reference Code
import pandas as pd
df = pd.DataFrame({'A':[1,2],'B':[4,5],'C':[7,8]})
df2 = df[['A','C']]
print(df2.shape)
A
(2, 3)
B
(3, 2)
C
(2, 2)
D
(1, 2)
Answer: (2, 2)
Explanation: Two rows remain and only columns A and C are selected, giving shape (2, 2).
Q-24
What will be the result of the following operation?
Hard
Pandas Series
Sample Data
Series values: [10, 20, 30]
Reference Code
import pandas as pd
s = pd.Series([10, 20, 30])
print(s + 5)
A
Each value increased by 5
B
Only first value increased
C
TypeError
D
No change in values
Answer: Each value increased by 5
Explanation: Pandas Series supports vectorized operations; 5 is added to every element.
Q-25
Which parameter ensures that the first column in a CSV file becomes the index?
Hard
CSV Import Export
A
index_col=0
B
use_index=True
C
set_index=True
D
header=0
Answer: index_col=0
Explanation: index_col=0 tells Pandas to use the first column as the index.
Q-26
What happens when a Pandas Series is created from a dictionary?
Hard
Pandas Series
A
Dictionary keys become index labels
B
Dictionary values become index labels
C
Keys are ignored
D
Series cannot be created from dictionary
Answer: Dictionary keys become index labels
Explanation: When a Series is created from a dictionary, keys become the index.
Q-27
Which operation will result in alignment based on index labels?
Hard
Pandas Series
Sample Data
s1 index: [a, b, c]
s2 index: [b, c, d]
Reference Code
s3 = s1 + s2
A
Element-wise addition by position
B
Index-based alignment before addition
C
Raises an error
D
Only common values are added without alignment
Answer: Index-based alignment before addition
Explanation: Pandas aligns data based on index labels before performing operations.
Q-28
Which statement correctly distinguishes Pandas DataFrame from NumPy ndarray?
Hard
Pandas vs NumPy
A
DataFrame supports labeled rows and columns
B
ndarray supports labeled rows
C
Both support column names
D
Neither supports indexing
Answer: DataFrame supports labeled rows and columns
Explanation: A DataFrame supports both row and column labels, unlike ndarray.
Q-29
Which attribute returns both row and column labels of a DataFrame?
Hard
Pandas DataFrame
A
values
B
shape
C
axes
D
dtype
Answer: axes
Explanation: The axes attribute returns row index and column labels.
Q-30
Which statement about Pandas Series and NumPy ndarray is TRUE?
Hard
Pandas vs NumPy
A
Series supports heterogeneous data types
B
ndarray supports heterogeneous data types
C
Both support labeled indexing
D
ndarray supports missing value handling like Series
Answer: Series supports heterogeneous data types
Explanation: A Pandas Series can store heterogeneous data types, unlike ndarray.
Q-31
What will be the output of the following code?
Medium
Pandas Series
Sample Data
Series values: [2, 4, 6, 8]
Reference Code
import pandas as pd
s = pd.Series([2, 4, 6, 8])
print(s[1:3])
A
2, 4, 6
B
4, 6
C
6, 8
D
IndexError
Answer: 4, 6
Explanation: Slicing uses start index inclusive and end index exclusive, so values at positions 1 and 2 are returned.
Q-32
Which type of object is returned by the following expression?
Medium
Pandas DataFrame
Sample Data
DataFrame with columns: Name, Age, Marks
Reference Code
result = df[['Marks']]
A
Series
B
DataFrame
C
ndarray
D
list
Answer: DataFrame
Explanation: Using double square brackets returns a DataFrame, even when selecting a single column.
Q-33
What will be the shape of the DataFrame?
Medium
Pandas DataFrame
Sample Data
| A | B | C |
|---|---|---|
| 1 | 2 | 3 |
| 4 | 5 | 6 |
Reference Code
import pandas as pd
df = pd.DataFrame([[1,2,3],[4,5,6]], columns=['A','B','C'])
print(df.shape)
A
(2, 3)
B
(3, 2)
C
(1, 6)
D
(6, 1)
Answer: (2, 3)
Explanation: The DataFrame has 2 rows and 3 columns.
Q-34
Which method is most suitable to display only the last 3 rows of a DataFrame?
Medium
Pandas DataFrame
A
head(3)
B
tail(3)
C
info(3)
D
describe(3)
Answer: tail(3)
Explanation: tail(3) displays the last three rows of a DataFrame.
Q-35
Which statement correctly describes the output of df.info()?
Medium
Pandas DataFrame
A
Statistical summary of data
B
Data types and non-null counts
C
Only column names
D
Only index values
Answer: Data types and non-null counts
Explanation: info() shows column names, data types, and non-null counts.
Q-36
What will be the index of the resulting Series?
Medium
Pandas Series
Sample Data
Original Series index: [a, b, c]
Reference Code
import pandas as pd
s = pd.Series([10, 20, 30], index=['a','b','c'])
print(s[['a','c']])
A
[0, 1]
B
['a', 'c']
C
['b', 'c']
D
Index removed
Answer: ['a', 'c']
Explanation: When selecting by labels, the original index labels are preserved.
Q-37
Which parameter is used to prevent column headers from being written to a CSV file?
Medium
CSV Import Export
A
header=False
B
index=False
C
columns=False
D
names=False
Answer: header=False
Explanation: header=False prevents column names from being written to the CSV file.
Q-38
What happens if a Series is created with fewer index labels than values?
Medium
Pandas Series
A
Remaining values get default index
B
Index labels are repeated
C
Error is raised
D
Extra values are ignored
Answer: Error is raised
Explanation: The number of index labels must match the number of values; otherwise, an error occurs.
Q-39
Which statement about df.axes is correct?
Medium
Pandas DataFrame
A
Returns only column names
B
Returns only index values
C
Returns both row and column labels
D
Returns shape of DataFrame
Answer: Returns both row and column labels
Explanation: df.axes returns a list containing the index and column labels.
Q-40
Which operation will return a NumPy ndarray from a Pandas object?
Medium
Pandas vs NumPy
A
df.values
B
df.columns
C
df.index
D
df.shape
Answer: df.values
Explanation: The values attribute returns the underlying NumPy ndarray.
Q-41
What will be the output of the following code?
Hard
Pandas Series
Sample Data
Series s:
Index → a b c
Values → 10 20 30
Reference Code
import pandas as pd
s = pd.Series([10, 20, 30], index=['a','b','c'])
print(s[1])
A
10
B
20
C
30
D
KeyError
Answer: 20
Explanation: Integer-based indexing is positional here. Index position 1 refers to the second value, 20.
Q-42
What will be the output of the following code?
Hard
Pandas Series
Sample Data
Series s:
Index → a b c
Values → 10 20 30
Reference Code
import pandas as pd
s = pd.Series([10, 20, 30], index=['a','b','c'])
print(s['b':'c'])
A
20, 30
B
20 only
C
30 only
D
KeyError
Answer: 20, 30
Explanation: Label-based slicing in Pandas is inclusive of both start and end labels.
Q-43
What will be the shape of the resulting DataFrame?
Hard
Pandas DataFrame
Sample Data
| Name | Maths | Science |
|---|---|---|
| A | 80 | 70 |
| B | 60 | 75 |
| C | 90 | 85 |
Reference Code
import pandas as pd
df = pd.DataFrame({
'Name':['A','B','C'],
'Maths':[80,60,90],
'Science':[70,75,85]
})
df2 = df[['Maths','Science']]
print(df2.shape)
A
(3, 2)
B
(2, 3)
C
(3, 3)
D
(2, 2)
Answer: (3, 2)
Explanation: All three rows remain, and only two columns are selected, giving shape (3, 2).
Q-44
What will be the output of the following operation?
Hard
Pandas Series
Sample Data
Series s1 index: a, b, c
Series s2 index: b, c, d
Reference Code
import pandas as pd
s1 = pd.Series([10,20,30], index=['a','b','c'])
s2 = pd.Series([1,2,3], index=['b','c','d'])
print(s1 + s2)
A
Values added by position
B
Values added only for matching indices
C
Error due to different indices
D
Only s1 values printed
Answer: Values added only for matching indices
Explanation: Pandas aligns Series by index labels. Only matching indices (b, c) are added; others become NaN.
Q-45
What will be the data type of the object returned?
Hard
Pandas DataFrame
Sample Data
DataFrame df with columns: Name, Marks
Reference Code
result = df.loc[:, 'Marks']
A
Series
B
DataFrame
C
ndarray
D
list
Answer: Series
Explanation: Selecting a single column using .loc returns a Pandas Series.
Q-46
What will be the output of the following code?
Hard
Pandas DataFrame
Sample Data
| A | B |
|---|---|
| 1 | 4 |
| 2 | 5 |
| 3 | 6 |
Reference Code
import pandas as pd
df = pd.DataFrame({'A':[1,2,3],'B':[4,5,6]})
print(df.iloc[1:3, 0])
A
2, 3
B
1, 2
C
2 only
D
IndexError
Answer: 2, 3
Explanation: iloc slicing is positional and end-exclusive. Rows 1 and 2 from column 0 give values 2 and 3.
Q-47
What happens when the following CSV file is read?
Hard
CSV Import Export
Sample Data
CSV file marks.csv:
Roll,Marks
1,80
2,75
Reference Code
import pandas as pd
df = pd.read_csv('marks.csv', index_col=0)
A
Roll becomes index
B
Marks becomes index
C
Default index is created
D
Error occurs
Answer: Roll becomes index
Explanation: index_col=0 makes the first column (Roll) the DataFrame index.
Q-48
Which rows will be displayed by the following statement?
Hard
Pandas DataFrame
Sample Data
| Roll | Marks |
|---|---|
| 1 | 40 |
| 2 | 55 |
| 3 | 70 |
| 4 | 85 |
Reference Code
print(df[df['Marks'] >= 60])
A
Roll 1 and 2
B
Roll 3 and 4
C
Roll 2, 3, 4
D
All rows
Answer: Roll 3 and 4
Explanation: Boolean indexing selects rows where Marks are 60 or more: Roll 3 and 4.
Q-49
What will be the output of the following code?
Hard
Pandas vs NumPy
Sample Data
Series s:
Values → 10, 20, 30
Reference Code
import pandas as pd
s = pd.Series([10,20,30])
print(s.values)
A
Pandas Series
B
Python list
C
NumPy ndarray
D
Tuple
Answer: NumPy ndarray
Explanation: The values attribute returns the underlying NumPy ndarray.
Q-50
Which statement best explains the behaviour of the following code?
Hard
Pandas Series
Sample Data
Series s with index a, b, c
Reference Code
s = pd.Series([1,2,3], index=['a','b','c'])
print(s + 1)
A
Addition happens element-wise using index alignment
B
Only first element is incremented
C
Error due to incompatible types
D
Series is unchanged
Answer: Addition happens element-wise using index alignment
Explanation: Pandas supports vectorized operations; scalar addition is applied to each element.
◀
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
▶