100+ Python Pandas Questions for CBSE Class 12 Board Exam 2026 | IP & CS

Published on October 3, 2025 by @mritxperts

Part 1: Foundational Concepts

1. What is Pandas? An open-source Python library used for high-performance data manipulation and analysis. 🐼

2. What are the two primary data structures in Pandas? Series (1-dimensional) and DataFrame (2-dimensional).

3. What is the standard alias for importing pandas? pd (as in import pandas as pd).

4. What is Matplotlib? A comprehensive library for creating static, animated, and interactive visualizations (plots and graphs) in Python. 📊

5. What is the standard alias for importing matplotlib.pyplot? plt (as in import matplotlib.pyplot as plt).


Part 2: Pandas Series

6. What is a Series? A one-dimensional labeled array capable of holding data of any type. Think of it as a single column of a spreadsheet.

7. What is an Index in a Series? The labels associated with the data values. If not specified, a default integer index (0, 1, 2, ...) is created.

8. What does S.values return? It returns the data of the Series S as a NumPy array.

9. What does S.index return? It returns the index (labels) of the Series S.

10. What is the use of the S.head() method? To view the first few rows of the Series (5 by default).

11. What is the use of the S.tail() method? To view the last few rows of the Series (5 by default).

12. What does the S.size attribute give? The total number of elements in the Series.

13. What is Vectorization in Pandas? Applying an operation or function to an entire Series at once, without using explicit loops.


Part 3: Pandas DataFrame

14. What is a DataFrame? A two-dimensional labeled data structure with columns of potentially different types. It’s like a table, spreadsheet, or SQL table.

15. What are the two axes in a DataFrame? axis=0 for rows (index) and axis=1 for columns.

16. What does df.shape return? A tuple representing the dimensions of the DataFrame: (number of rows, number of columns).

17. How do you access the column labels of a DataFrame df? Using the df.columns attribute.

18. What does df.T do? It transposes the DataFrame, swapping its rows and columns.

19. How do you select a single column named ‘Name’ from df? Using df['Name'].

20. What is the purpose of df.info()? To get a concise summary of the DataFrame, including data types and non-null counts.

21. What does df.describe() do? It generates descriptive statistics (mean, std, min, max, etc.) for the numerical columns.


Part 4: Data Accessing & Selection

22. What is the difference between .loc and .iloc?

  • .loc is used for label-based indexing.
  • .iloc is used for integer position-based indexing.

23. How do you select the first 5 rows of a DataFrame df? df.iloc[0:5] or simply df.head().

24. What is Boolean Indexing? Using a boolean condition to filter data. For example, df[df['Age'] > 18] selects rows where the ‘Age’ is greater than 18.


Part 5: File Operations (CSV)

25. Which function is used to read a CSV file into a DataFrame? pd.read_csv().

26. Which function is used to write a DataFrame to a CSV file? df.to_csv().

27. How do you prevent the index from being written to the CSV file? Use the parameter index=False in df.to_csv().

28. What does the index_col parameter do in read_csv? It sets one of the columns from the CSV file as the DataFrame’s index.

29. What does the sep parameter specify in read_csv? The delimiter or separator used in the file (e.g., sep=';').

30. What does the usecols parameter do? It allows you to read only a specific subset of columns from the CSV file.


Part 6: Data Manipulation & Cleaning

31. How do you add a new column named ‘Total’ to a DataFrame df? By simple assignment: df['Total'] = ...

32. How do you delete a column? Using the df.drop() method with axis=1. Example: df.drop('ColumnName', axis=1).

33. How do you delete a row by its label? Using the df.drop() method with axis=0. Example: df.drop('RowLabel', axis=0).

34. What is NaN? It stands for “Not a Number” and is the standard representation for missing data in Pandas.

35. How do you check for missing values in a DataFrame? Using the df.isnull() or df.notnull() methods.

36. What does df.isnull().sum() return? A Series containing the count of NaN values in each column.

37. What does df.dropna() do? It removes rows (or columns) that contain missing values (NaN).

38. What does df.fillna(0) do? It replaces all NaN values in the DataFrame with 0.

39. How do you sort a DataFrame by the values in the ‘Score’ column? df.sort_values(by='Score').

40. What is the purpose of the ascending=False parameter in sorting? To sort the data in descending order.

41. What is the purpose of the df.groupby() function? To split the data into groups based on some criteria to perform aggregate operations (like sum, mean, count).

42. What does df['Category'].value_counts() do? It returns a Series containing the counts of unique values in the ‘Category’ column.

43. How do you rename a column ‘OldName’ to ‘NewName’? df.rename(columns={'OldName': 'NewName'}).


Part 7: Plotting

44. Which function displays the plot window? plt.show().

45. What is the easiest way to plot data from a DataFrame? Using the DataFrame’s built-in .plot() method (e.g., df.plot()).

46. How do you specify the type of plot (e.g., bar, line, pie)? Using the kind parameter in the .plot() method. E.g., df.plot(kind='bar').

47. What is a line plot (kind='line') used for? Typically for showing trends over a continuous interval like time.

48. What is a bar plot (kind='bar') used for? For comparing quantities across different categories.

49. What is a histogram (kind='hist') used for? To show the frequency distribution of a set of continuous numerical data.

50. What function sets the title of a plot? plt.title('My Plot Title').

51. What functions are used to label the X and Y axes? plt.xlabel('X-axis Label') and plt.ylabel('Y-axis Label').

52. What is a legend on a plot? A small box or area that identifies the different data series in a plot. It can be controlled with plt.legend().

53. How do you make a horizontal bar chart? By setting kind='barh'.


Long Question/Ans


Part 1: Core Pandas – Series (1-Mark Questions)

Q1: What is a Pandas Series? A Series is a one-dimensional labeled array, similar to a column in a spreadsheet. It can hold data of any type (integer, string, float, python objects, etc.).

Q2: Write the command to import the pandas library with the alias pd. import pandas as pd

Q3: How do you create a Series from a Python list L = [10, 20, 30]?

Python

import pandas as pd
L = [10, 20, 30]
S = pd.Series(L)

Q4: What is the primary difference between a NumPy array and a Pandas Series? The main difference is that a Series has an explicitly defined index associated with its values, whereas a NumPy array has an implicit integer index.

Q5: How do you create a Series from a dictionary D = {'a': 1, 'b': 2, 'c': 3}?

Python

import pandas as pd
D = {'a': 1, 'b': 2, 'c': 3}
S = pd.Series(D)
# The dictionary keys become the Series index.

Q6: Consider the Series S. What will be the output of S.values and S.index? S.values will return a NumPy array containing the data [1, 2, 3]. S.index will return an Index object ['a', 'b', 'c'].

Q7: How can you access the element with the label ‘b’ in the Series S from Q5? You can use S['b'] or S.loc['b'].

Q8: What do the .head(2) and .tail(2) functions do on a Series? .head(2) returns a new Series containing the first 2 elements. .tail(2) returns a new Series containing the last 2 elements.

Q9: Write the code to create a Series with the data [5, 10, 15, 20] and a custom index ['w', 'x', 'y', 'z'].

Python

import pandas as pd
data = [5, 10, 15, 20]
index = ['w', 'x', 'y', 'z']
S = pd.Series(data, index=index)

Q10: What does the size attribute of a Series return? The size attribute returns the total number of elements in the Series.


Part 2: Core Pandas – DataFrame (1 & 2-Mark Questions)

Q11: What is a Pandas DataFrame? A DataFrame is a two-dimensional, size-mutable, and potentially heterogeneous tabular data structure with labeled axes (rows and columns). It’s like a spreadsheet or a SQL table.

Q12: How do you create a DataFrame from the dictionary data = {'Name': ['Anu', 'Bob'], 'Age': [21, 25]}?

Python

import pandas as pd
data = {'Name': ['Anu', 'Bob'], 'Age': [21, 25]}
df = pd.DataFrame(data)

Q13: What does the df.shape attribute return for the DataFrame created in Q12? It will return a tuple (2, 2), representing (number of rows, number of columns).

Q14: What is the command to display the first 3 rows of a DataFrame df? df.head(3)

Q15: What is the command to display the column labels of a DataFrame df? df.columns

Q16: Explain the difference between loc and iloc for selecting data from a DataFrame.

  • .loc is label-based, meaning you have to specify the names of the rows and columns.
  • .iloc is integer-position based, meaning you have to specify rows and columns by their integer position (starting from 0).

Q17: Given a DataFrame df, how would you select the column named ‘Score’? df['Score'] or df.Score (if the column name is a valid Python identifier).

Q18: How do you add a new column ‘Grade’ with values ['A', 'B'] to the DataFrame from Q12? df['Grade'] = ['A', 'B']

Q19: What is the command to transpose a DataFrame df? df.T

Q20: How can you delete the column named ‘Age’ from a DataFrame df? df.drop('Age', axis=1) (Note: axis=1 specifies that we are dropping a column. To make the change permanent, use inplace=True or reassign: df = df.drop(...))

Q21: What does the df.info() method do? It prints a concise summary of the DataFrame, including the index dtype, column dtypes, non-null values, and memory usage.

Q22: What does the df.describe() method show? It generates descriptive statistics for the numerical columns, such as count, mean, standard deviation, min, max, and quartiles.


Part 3: CSV File Handling (2-Mark Questions)

Q23: Write the Python statement to read a file named student.csv into a pandas DataFrame df. df = pd.read_csv('student.csv')

Q24: How would you write the contents of a DataFrame df to a new CSV file named output.csv? df.to_csv('output.csv')

Q25: When writing a DataFrame to a CSV, an extra unnamed column is often created. How do you prevent this? Use the index=False parameter. df.to_csv('output.csv', index=False)

Q26: Your CSV file data.csv uses a semicolon (;) as a separator instead of a comma. How do you read it correctly? df = pd.read_csv('data.csv', sep=';')

Q27: How can you read a CSV file and specify the ‘RollNo’ column as the index for the DataFrame? df = pd.read_csv('student.csv', index_col='RollNo')

Q28: How do you read only specific columns, ‘Name’ and ‘Marks’, from student.csv? df = pd.read_csv('student.csv', usecols=['Name', 'Marks'])

Q29: What parameter in pd.read_csv() would you use if your CSV file has no header row? header=None. Pandas will automatically assign integer column names: 0, 1, 2, … df = pd.read_csv('data.csv', header=None)


Part 4: Data Manipulation & Analysis (2 & 3-Mark Questions)

Q30: Given a DataFrame df with a ‘Marks’ column, how do you find the average marks? df['Marks'].mean()

Q31: How do you sort the DataFrame df based on the ‘Marks’ column in descending order? df.sort_values(by='Marks', ascending=False)

Q32: How can you check for missing/null values in a DataFrame df? df.isnull() or df.isnull().sum() to get a count of nulls per column.

Q33: Write the command to drop all rows that contain any missing values from a DataFrame df. df.dropna()

Q34: How do you fill all NaN values in a DataFrame df with the value 0? df.fillna(0)

Q35: Consider a DataFrame sales with columns ‘Region’ and ‘Revenue’. How do you calculate the total revenue for each region? sales.groupby('Region')['Revenue'].sum()

Q36: How do you select all rows from a DataFrame df where the value in the ‘Age’ column is greater than 25? df[df['Age'] > 25]

Q37: What is the command to rename the column ‘Name’ to ‘Student_Name’ in DataFrame df? df.rename(columns={'Name': 'Student_Name'}) (Note: Use inplace=True to modify the original DataFrame.)

Q38: How do you count the occurrences of each unique value in the ‘City’ column of a DataFrame df? df['City'].value_counts()

Q39: How would you add a new row to a DataFrame df? While direct appending is possible (df.loc[new_index] = [values]), the modern and recommended approach is to create a new DataFrame for the row and use pd.concat():

Python

new_row = pd.DataFrame([{'Name': 'Ram', 'Age': 23}])
df = pd.concat([df, new_row], ignore_index=True)

Part 5: Plotting with Matplotlib (2 & 3-Mark Questions)

Q40: Write the command to import the pyplot module from matplotlib with the alias plt. import matplotlib.pyplot as plt

Q41: Given a DataFrame df with columns ‘Year’ and ‘Sales’, write the code to create a simple line plot.

Python

import matplotlib.pyplot as plt
df.plot(x='Year', y='Sales', kind='line')
plt.title('Yearly Sales')
plt.xlabel('Year')
plt.ylabel('Sales')
plt.show()

Q42: How do you create a vertical bar chart from the data in Q41? Change kind='line' to kind='bar'. df.plot(x='Year', y='Sales', kind='bar')

Q43: How do you create a horizontal bar chart? Change kind='bar' to kind='barh'. df.plot(x='Year', y='Sales', kind='barh')

Q44: What is a histogram and what does it represent? How do you create one for a ‘Marks’ column in a DataFrame df? A histogram is a graphical representation of the distribution of numerical data. It groups numbers into ranges (bins) and shows the frequency of data in each range. df['Marks'].plot(kind='hist') plt.show()

Q45: How can you create a pie chart to show the proportion of students in different sections (‘A’, ‘B’, ‘C’) stored in a ‘Section’ column of a DataFrame df? First, get the counts of each section, then plot.

Python

section_counts = df['Section'].value_counts()
section_counts.plot(kind='pie', autopct='%1.1f%%')
plt.ylabel('') # Hides the 'Section' label on the side
plt.title('Student Distribution by Section')
plt.show()

Q46: How do you add a legend to your plot? The legend is often added automatically when plotting from a DataFrame. You can customize it using plt.legend(). For example: plt.legend(['Sales Data']).


Part 6: Applied/Case-Study Questions (3-5 Marks)

Assume you have a file named Product.csv with the following content:

Code snippet

PID,PName,Price,Category
101,Laptop,75000,Electronics
102,Keyboard,2500,Electronics
103,Book,800,Stationery
104,Pen,50,Stationery
105,Smartphone,45000,Electronics

Q47: Write a Python program to read the Product.csv file into a DataFrame and display its first 3 rows.

Python

import pandas as pd
df = pd.read_csv("Product.csv")
print(df.head(3))

Output:

   PID     PName   Price     Category
0  101    Laptop   75000  Electronics
1  102  Keyboard    2500  Electronics
2  103      Book     800   Stationery

Q48: Using the DataFrame from Q47, write the code to display the PName and Price of all products where the Category is ‘Electronics’.

Python

electronics_df = df[df['Category'] == 'Electronics']
print(electronics_df[['PName', 'Price']])

Output:

        PName  Price
0      Laptop  75000
1    Keyboard   2500
4  Smartphone  45000

Q49: Using the DataFrame from Q47, calculate and display the average price of products for each category.

Python

avg_price = df.groupby('Category')['Price'].mean()
print(avg_price)

Output:

Category
Electronics    40833.333333
Stationery       425.000000
Name: Price, dtype: float64

Q50: Add a new column named Discount_Price to the DataFrame which is 90% of the original Price. Display the entire DataFrame after adding the column.

Python

df['Discount_Price'] = df['Price'] * 0.90
print(df)

Output:

   PID       PName   Price     Category  Discount_Price
0  101      Laptop   75000  Electronics         67500.0
1  102    Keyboard    2500  Electronics          2250.0
2  103        Book     800   Stationery           720.0
3  104         Pen      50   Stationery            45.0
4  105  Smartphone   45000  Electronics         40500.0

Q51: Write a complete program to read Product.csv and create a bar chart showing the price of each product. The product name should be on the x-axis and the price on the y-axis.

Python

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv("Product.csv")
df.plot(x='PName', y='Price', kind='bar', figsize=(8, 5))

plt.title('Product Prices')
plt.xlabel('Product Name')
plt.ylabel('Price (INR)')
plt.xticks(rotation=45) # Rotate x-axis labels for better readability
plt.tight_layout() # Adjust layout
plt.show()

Q52: Write the output of the following code, given the DataFrame df from Q47.

Python

print(df.iloc[1:4, 1:3])

Answer: iloc is integer-based. It will select rows with index 1, 2, 3 (4 is exclusive) and columns with index 1, 2 (3 is exclusive). Output:

      PName  Price
1  Keyboard   2500
2      Book    800
3       Pen     50

Q53: Write the output of the following code, assuming the PID column is set as the index.

Python

df = pd.read_csv("Product.csv", index_col='PID')
print(df.loc[103])

Answer: .loc is label-based. It will select the row where the index label is 103. Output:

PName         Book
Price          800
Category    Stationery
Name: 103, dtype: object