This practice paper contains various questions focusing on how to work with DataFrame attributes using different options. It is an important topic for Class XII CBSE Board students, and through this practice paper, they will learn about various concepts associated with modifying DataFrames easily.
I have already explained the creation, accessing elements, adding and deleting rows and columns in my previous practice papers. They are:
- DataFrame Practice Questions with Solutions (Part-I) – for creation DataFrame
- DataFrame Practice Questions with Solutions (Part-2) – for accessing DataFrame
- DataFrame Practice Questions with Solutions (Part-3) – for add/delete rows/columns into DataFrame.
Let’s start with Practice Paper 4
Question: What are DataFrame attributes? | ||||||||||||||||||||||||
Answer : DataFrame attributes are properties or characteristics of a DataFrame object that provide information about its structure, content, and metadata. These attributes are accessed using dot notation and provide information without modifying the original DataFrame. Syntax : <DataFrame Object Name>.<attribute name> | ||||||||||||||||||||||||
Question : List some common attributes along with their descriptions. | ||||||||||||||||||||||||
Answer: | ||||||||||||||||||||||||
Question : How size attribute is different from shape attribute? | ||||||||||||||||||||||||
Answer : size Attribute : Returns the total number of elements in the DataFrame, which is the product of the number of rows and columns. If a DataFrame has 5 rows and 3 columns, df.size would return 15 .shape Attribute : Returns a tuple representing the dimensions of the DataFrame (number of rows, number of columns). If a DataFrame has 5 rows and 3 columns, | ||||||||||||||||||||||||
Question: Create an empty DataFrame and then, using the appropriate attribute, check whether it is empty or not. | ||||||||||||||||||||||||
Answer : | ||||||||||||||||||||||||
Question : Given a DataFrame namely “employee” that stores the details of employees: | ||||||||||||||||||||||||
a) Display the row labels of employees | ||||||||||||||||||||||||
Answer : For viewing the row labels or names in a DataFrame, you should use the index attribute, like this: | ||||||||||||||||||||||||
b) Display the columns labels of employees | ||||||||||||||||||||||||
Answer : For viewing the columns labels or names in a DataFrame, you should use the columns attribute, like this: | ||||||||||||||||||||||||
c) Display the data types of each columns of employees | ||||||||||||||||||||||||
d) Find the dimensions of the employee dataframe. | ||||||||||||||||||||||||
e) Find number of rows and columns of employee dataframe. | ||||||||||||||||||||||||
f) Find total numbers of rows and columns of employee dataframe. | ||||||||||||||||||||||||
g) How can you see all values of dataframe employee with the help of attributes? | ||||||||||||||||||||||||
h) Find number of rows and number of columns in employee without using shape attribute. | ||||||||||||||||||||||||
i) Check employee dataframe is empty or not. | ||||||||||||||||||||||||
Question : What do you mean by Transpose a DataFrame? Give example. | ||||||||||||||||||||||||
Answer : Transposing a DataFrame in pandas means switching its rows and columns, effectively swapping the axes. This operation transforms the DataFrame such that the rows become columns and vice versa. In pandas, you can use the .transpose() method or the .T attribute to achieve this. | ||||||||||||||||||||||||
Question : How are DataFrame attributes different from DataFrame functions? | ||||||||||||||||||||||||
Answer :
| ||||||||||||||||||||||||
Question : List some common attributes along with their descriptions. | ||||||||||||||||||||||||
Answer :
| ||||||||||||||||||||||||
Question : Consider the following dataframe “Details” and answers the following questions : | ||||||||||||||||||||||||
a) Display first 3 rows of “details” dataframe using appropriate function. | ||||||||||||||||||||||||
b) Display last 4 rows of “details” dataframe using appropriate functions. | ||||||||||||||||||||||||
c) Display the DataFrame by sorting in ascending order based on the ‘Name’ column. | ||||||||||||||||||||||||
d) Display the DataFrame by sorting in descending order based on the ‘Age’ column. | ||||||||||||||||||||||||
e) Display the DataFrame by sorting in descending order based on the indexes/row label. | ||||||||||||||||||||||||