Class 12 IP Worksheet: DataFrame Attributes AND CSV FILE WORKSHEET NO 2

Class 12 IP Worksheet: DataFrame Attributes

Name:
Class:
Roll Number:
Date:


Section A: Multiple Choice Questions (MCQs)

  1. Which attribute of a DataFrame returns the number of rows and columns?

    • a) df.shape
    • b) df.size
    • c) df.ndim
    • d) df.columns
  2. Which attribute gives the data types of the columns in a DataFrame?

    • a) df.dtypes
    • b) df.types
    • c) df.columns
    • d) df.info()
  3. What does the df.index attribute return?

    • a) The names of the columns
    • b) The labels of the rows (index labels)
    • c) The data type of the DataFrame
    • d) The shape of the DataFrame
  4. Which attribute would you use to get a summary of non-null values for each column in a DataFrame?

    • a) df.describe()
    • b) df.columns
    • c) df.notnull()
    • d) df.count()

Section B: Short Answer Questions

  1. What is the use of the df.columns attribute in a DataFrame?

  2. Explain the difference between df.size and df.shape.

  3. How can you use the df.T attribute? Provide an example.

  4. Describe what the df.ndim attribute returns and its significance.

Section C: Long Answer Questions

  1. Given the following DataFrame, write code to display and explain the use of each of the following attributes: df.shapedf.columnsdf.indexdf.dtypes, and df.size.

    data = {
    'Product': ['Laptop', 'Tablet', 'Smartphone'],
    'Price': [1000, 500, 800],
    'Stock': [50, 100, 75]
    }
    df = pd.DataFrame(data)


  2. Create a DataFrame with the following data and perform the following tasks using DataFrame attributes:

    data = {
    'Name': ['Alice', 'Bob', 'Charlie'],
    'Math': [90, 85, 78],
    'Science': [95, 80, 88],
    'English': [85, 87, 92]
    }
    df = pd.DataFrame(data)
    • a)Use df.T to transpose the DataFrame and display it.
    • b) Find the data type of each column using df.dtypes.
    • c) Display the number of dimensions of the DataFrame using df.ndim.



Section D: Practical Application

  1. Load a DataFrame from a CSV file and use the following attributes to understand its structure and data:

    • a) df.info()
    • b) df.head()
    • c) df.columns
    • d) df.shape
  2. Create a DataFrame to record student attendance with columns: 'Name', 'Present_Days', 'Total_Days'. Using the attributes df.columnsdf.index, and df.dtypes, analyze the DataFrame and perform the following tasks:

    • a) Rename the columns to 'Student_Name', 'Days_Present', and 'Total_Attendance'.
    • b) Reset the index to start from 1 instead of 0.
    • c) Display the new data types of the columns.

    3. Load a dataset from a CSV file into a DataFrame. Using the following attributes, perform an in-depth analysis:

    • A) df.columns
    • B) df.dtypes
    • C) df.index

    Instructions: Analyze the output to determine the structure, data types, and memory usage of the dataset. Propose changes to optimize memory and enhance data handling.


4. Create a DataFrame with at least 5 rows and 4 columns. Use the following attributes to perform operations and explain the output:

  • a) df.columns
  • b) df.index
  • c) df.dtypes
  • d) df.T

5. Create a DataFrame to record student attendance with columns: 'Name', 'Present_Days', 'Total_Days'. Using the attributes df.columnsdf.index, and df.dtypes, analyze the DataFrame and perform the following tasks:

  • a) Rename the columns to 'Student_Name', 'Days_Present', and 'Total_Attendance'.
  • b) Reset the index to start from 1 instead of 0.
  • c) Display the new data types of the columns.

6. Load a DataFrame from a CSV file and use the following attributes to understand its structure and data:

  • a) df.head()
  • b) df.columns
  • c) df.shape




Post a Comment

0 Comments