CBSERanker

Loading

Worksheet #24090601 Introduction to Python Libraries—Pandas, Matplotlib, Data Structures in Pandas

Worksheet #24090601 Introduction to Python Libraries—Pandas, Matplotlib, Data Structures in Pandas

Multiple Choice Questions (MCQs)

  1. What is the primary purpose of the Pandas library in Python?
    • a) Image Processing
    • b) Numerical Computations
    • c) Data Manipulation and Analysis
    • d) Web Development
  2. Which of the following is used to create a one-dimensional labeled array in Pandas?
    • a) DataFrame
    • b) Series
    • c) Dictionary
    • d) List
  3. How do you create a Pandas DataFrame from a dictionary?
    • a) pd.DataFrame.from_dict()
    • b) pd.read_csv()
    • c) pd.Series()
    • d) pd.read_dict()
  4. Which function is used to view the first few records of a DataFrame in Pandas?
    • a) .tail()
    • b) .head()
    • c) .sample()
    • d) .view()
  5. In Pandas, the function used to select rows based on a condition is called:
    • a) Selection indexing
    • b) Conditional indexing
    • c) Boolean indexing
    • d) Scalar indexing
  6. Which of the following methods can be used to read data from a CSV file into a DataFrame?
    • a) pd.read_csv()
    • b) pd.read_excel()
    • c) pd.load_csv()
    • d) pd.readfile()
  7. What is the default axis for operations like adding or deleting columns in a DataFrame?
    • a) Axis 0 (rows)
    • b) Axis 1 (columns)
    • c) Axis 2 (layers)
    • d) No default axis
  8. Which of the following will correctly slice the first three elements from a Pandas Series named s?
    • a) s.slice(0, 2)
    • b) s[0:3]
    • c) s.index(0:2)
    • d) s.cut(0, 3)
  9. How do you rename a column in a Pandas DataFrame?
    • a) df.rename_column()
    • b) df.columns['old_name'] = 'new_name'
    • c) df.rename(columns={'old_name': 'new_name'})
    • d) df.change_column()
  10. Which library is typically used with Pandas for creating visualizations in Python?
    • a) Seaborn
    • b) Numpy
    • c) Matplotlib
    • d) Scikit-learn

Programming Questions

  1. Create a Pandas Series from a NumPy ndarray and perform a mathematical operation such as adding 10 to all values.
  2. Write a Python program to create a Series from a dictionary where the keys are student names and the values are their marks. Display the Series.
  3. Create a Pandas DataFrame from a list of dictionaries containing information about students (name, age, and grade). Display the first five rows.
  4. Write a program to read a CSV file containing employee data (name, department, salary) into a Pandas DataFrame and display the DataFrame.
  5. Create a Pandas Series and demonstrate the use of .head() and .tail() functions on the Series.
  6. Write a Python program to create a DataFrame from a dictionary of Series. Perform an operation to delete a column and display the modified DataFrame.
  7. Given a DataFrame of sales data (product, price, quantity), write a program to add a new column that shows the total sales for each product (price * quantity).
  8. Create a Pandas DataFrame from a CSV file and demonstrate how to select rows using Boolean indexing where the column ‘Age’ is greater than 30.
  9. Write a Python program to rename the columns of a Pandas DataFrame (e.g., ‘old_name’ to ‘new_name’) and display the updated DataFrame.
  10. Write a Python program to export a DataFrame of student marks to a CSV file.

Leave a Reply

Your email address will not be published. Required fields are marked *