Class 12 IP Worksheet: DataFrame Attributes
Section A: Multiple Choice Questions (MCQs)
Which attribute of a DataFrame returns the number of rows and columns?
- a)
df.shape - b)
df.size - c)
df.ndim - d)
df.columns
- a)
Which attribute gives the data types of the columns in a DataFrame?
- a)
df.dtypes - b)
df.types - c)
df.columns - d)
df.info()
- a)
What does the
df.indexattribute 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
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()
- a)
Section B: Short Answer Questions
- What is the use of the
df.columnsattribute in a DataFrame? - Explain the difference between
df.sizeanddf.shape. - How can you use the
df.Tattribute? Provide an example. Describe what the
df.ndimattribute returns and its significance.
Section C: Long Answer Questions
Given the following DataFrame, write code to display and explain the use of each of the following attributes:
df.shape,df.columns,df.index,df.dtypes, anddf.size.data = {'Product': ['Laptop', 'Tablet', 'Smartphone'],'Price': [1000, 500, 800],'Stock': [50, 100, 75]}df = pd.DataFrame(data)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.Tto 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.
- a)Use
Section D: Practical Application
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
- a)
Create a DataFrame to record student attendance with columns: 'Name', 'Present_Days', 'Total_Days'. Using the attributes
df.columns,df.index, anddf.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.columns, df.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



0 Comments
Please do note create link post in comment section