Informatics Practices

Pandas DataFrame & CSV Files MCQs | 25 Practice Questions with Answers | CBSE Class 12 Informatics Practices (IP)

Class 12 · Informatics Practices

Pandas DataFrame & CSV Files MCQs (25 Questions)

Practice these multiple-choice questions to strengthen your understanding of Pandas DataFrame and CSV File Handling. Click Show Answer to reveal the correct answer and explanation.


Q1. A DataFrame in Pandas is:

A. A one-dimensional labeled array.
B. A two-dimensional labeled data structure.
C. A Python dictionary.
D. A NumPy array.

Show Answer

Answer: B. A two-dimensional labeled data structure.

Explanation: A DataFrame stores data in rows and columns, similar to a spreadsheet or database table.


Q2. Which function is used to create a DataFrame?

A. pd.Series()
B. pd.DataFrame()
C. DataFrame.create()
D. create()

Show Answer

Answer: B.

Explanation: The pd.DataFrame() constructor is used to create a DataFrame.


Q3. A DataFrame can be created from:

A. Dictionary of Series
B. List of Dictionaries
C. CSV File
D. All of these

Show Answer

Answer: D. All of these.

Explanation: Pandas supports multiple ways to create a DataFrame.


Q4. Which function is commonly used to read a CSV file into a DataFrame?

A. readfile()
B. open()
C. pd.read_csv()
D. csv.load()

Show Answer

Answer: C.

Explanation: pd.read_csv() imports CSV data into a DataFrame.


Q5. Which method exports a DataFrame to a CSV file?

A. write_csv()
B. save()
C. to_csv()
D. export()

Show Answer

Answer: C.

Explanation: The to_csv() method writes DataFrame data to a CSV file.


Q6. Which method displays the first five rows of a DataFrame by default?

A. first()
B. head()
C. display()
D. show()

Show Answer

Answer: B.

Explanation: head() displays the first five rows unless another number is specified.


Q7. Which method displays the last five rows of a DataFrame?

A. last()
B. end()
C. tail()
D. bottom()

Show Answer

Answer: C.

Explanation: tail() returns the last five rows by default.


Q8. Which parameter is commonly used to assign custom row labels while creating a DataFrame?

A. labels
B. rows
C. index
D. columns

Show Answer

Answer: C.

Explanation: The index parameter specifies row labels.


Q9. Which of the following is TRUE about a DataFrame?

A. It can contain different data types.
B. It stores data in rows and columns.
C. Each column has a name.
D. All of these.

Show Answer

Answer: D.

Explanation: A DataFrame is a flexible two-dimensional data structure supporting multiple data types.


Q10. Which statement is used to display the complete DataFrame?

A. Simply writing the DataFrame name
B. print(DataFrame)
C. Both A and B
D. None of these

Show Answer

Answer: C.

Explanation: Both approaches display the DataFrame in Python.


Q11. Which operation is used to add a new column to a DataFrame?

A. df["Marks"] = values
B. df.addrow()
C. df.insertrow()
D. df.column()

Show Answer

Answer: A.

Explanation: Assigning values to a new column name creates a new column.


Q12. Which statement selects a single column named Name?

A. df["Name"]
B. df(Name)
C. df.Name()
D. df.select()

Show Answer

Answer: A.

Explanation: Square brackets are commonly used to select a column.


Q13. Which function removes a row or column from a DataFrame?

A. remove()
B. delete()
C. drop()
D. erase()

Show Answer

Answer: C.

Explanation: The drop() function removes rows or columns.


Q14. Which function is used to rename columns?

A. rename()
B. change()
C. replace()
D. update()

Show Answer

Answer: A.

Explanation: The rename() function changes row or column labels.


Q15. Which statement about DataFrames is correct?

A. They support row and column operations.
B. They support importing/exporting CSV files.
C. They support indexing and Boolean indexing.
D. All of these.

Show Answer

Answer: D.

Explanation: DataFrames provide extensive functionality for data manipulation and analysis.



Q16. Which statement is commonly used to iterate through the rows of a DataFrame?

A. iterrows()
B. rows()
C. iterate()
D. nextrow()

Show Answer

Answer: A. iterrows()

Explanation: The iterrows() method is commonly used to iterate through DataFrame rows.


Q17. Which indexer is used for label-based indexing in a DataFrame?

A. iloc[]
B. loc[]
C. index[]
D. labels[]

Show Answer

Answer: B. loc[]

Explanation: The loc[] indexer is used to access rows and columns using labels.


Q18. Boolean Indexing is mainly used to:

A. Sort data.
B. Filter records based on a condition.
C. Rename columns.
D. Delete rows.

Show Answer

Answer: B.

Explanation: Boolean indexing selects only those rows that satisfy a specified condition.


Q19. Which statement selects all students having marks greater than 80?

A. df[df["Marks"] > 80]
B. df["Marks" > 80]
C. df.select(80)
D. df.loc(80)

Show Answer

Answer: A.

Explanation: Boolean indexing is performed by specifying a condition inside square brackets.


Q20. Which method is used to export a DataFrame to a CSV file?

A. save_csv()
B. to_csv()
C. write_csv()
D. export_csv()

Show Answer

Answer: B. to_csv()

Explanation: The to_csv() method writes the contents of a DataFrame to a CSV file.


Q21. A school has a DataFrame containing the columns Name, Class, and Marks. Which statement will display only the students who scored more than 90 marks?

A. df[df["Marks"] > 90]
B. df.head(90)
C. df.tail(90)
D. df.loc["Marks"]

Show Answer

Answer: A.

Explanation: Boolean indexing filters rows based on a logical condition.


Q22. A company stores employee details in a CSV file. Which function should be used to import this data into a DataFrame?

A. pd.read_csv()
B. pd.import()
C. pd.load()
D. pd.open()

Show Answer

Answer: A.

Explanation: The read_csv() function reads data from a CSV file into a DataFrame.


Q23. Which of the following statements about CSV files is TRUE?

A. CSV stands for Comma Separated Values.
B. CSV files store tabular data.
C. Pandas can both read and write CSV files.
D. All of these.

Show Answer

Answer: D. All of these.

Explanation: CSV files are text files used to store tabular data, and Pandas provides functions to import and export them.


Q24. Which statement correctly describes DataFrame operations?

A. Columns can be added or deleted.
B. Rows can be filtered using Boolean indexing.
C. Columns can be renamed.
D. All of these.

Show Answer

Answer: D.

Explanation: DataFrames support a wide range of row and column operations, including filtering, renaming, adding, and deleting.


Q25. Which statement best summarizes the features of a Pandas DataFrame?

A. It stores data in rows and columns.
B. It supports indexing, filtering, and iteration.
C. It can import and export CSV files.
D. All of these.

Show Answer

Answer: D. All of these.

Explanation: A DataFrame is a powerful two-dimensional data structure that supports data storage, manipulation, indexing, filtering, iteration, and CSV file handling.


Answer Key

Q.No. Answer Q.No. Answer Q.No. Answer
1B11A21A
2B12A22A
3D13C23D
4C14A24D
5C15D25D
6B16A
7C17B
8C18B
9D19A
10C20B

Practice Tips

  • Remember the different ways to create a DataFrame:
    • Dictionary of Series
    • List of Dictionaries
    • CSV/Text Files using pd.read_csv()
  • Revise the commonly used DataFrame methods:
    • head() → Displays the first 5 rows.
    • tail() → Displays the last 5 rows.
    • drop() → Deletes rows or columns.
    • rename() → Renames row or column labels.
  • Understand column operations:
    • Add a new column
    • Select a column using df["ColumnName"]
    • Delete a column using drop()
    • Rename columns using rename()
  • Understand row selection techniques:
    • Label Indexing using loc[]
    • Boolean Indexing to filter records based on conditions
  • Remember CSV file functions:
    • pd.read_csv() → Import CSV file into a DataFrame.
    • to_csv() → Export DataFrame to a CSV file.
  • CBSE Tip: Most competency-based questions focus on choosing the correct Pandas function, understanding DataFrame operations, using loc[], applying Boolean indexing, and importing/exporting CSV files.