Informatics Practices
Consider the following DataFrame df and answer any four questions from (i)-(v):
| rollno | name | UT1 | UT2 | UT3 | UT4 |
|---|---|---|---|---|---|
| 1 | Prerna Singh | 24 | 24 | 20 | 22 |
| 2 | Manish Arora | 18 | 17 | 19 | 22 |
| 3 | Tanish Goel | 20 | 22 | 18 | 24 |
| 4 | Falguni Jain | 22 | 20 | 24 | 20 |
| 5 | Kanika Bhatnagar | 15 | 20 | 18 | 22 |
| 6 | Ramandeep Kaur | 20 | 15 | 22 | 24 |
The teacher needs to know the marks scored by the student with roll number 4. Help her identify the correct set of statement/s from the given options:
(a) df1 = df[df['rollno'] == 4]
print(df1)
(b) df1 = df[rollno == 4]
print(df1)
(c) df1 = df.[df.rollno = 4]
print(df1)
(d) df1 = df[df.rollno == 4]
print(df1)
Python Pandas
2 Likes
Answer
df1 = df[df.rollno == 4] print(df1)
Explanation
The statement df1 = df[df.rollno == 4] filters the DataFrame df to include only the rows where the roll number is equal to 4. This is accomplished using boolean indexing, where a boolean mask is created by checking if each row's rollno is equal to 4. Rows that satisfy this condition (True in the boolean mask) are selected, while others are excluded. The resulting DataFrame df1 contains only the rows corresponding to roll number 4 from the original DataFrame df.
Answered By
1 Like
Related Questions
Ekam, a Data Analyst with a multinational brand has designed the DataFrame df that contains the four quarters' sales data of different stores as shown below :
Store Qtr1 Qtr2 Qtr3 Qtr4 0 Store1 300 240 450 230 1 Store2 350 340 403 210 2 Store3 250 180 145 160 Answer the following questions :
(i) Predict the output of the following Python statement :
(a) print(df.size) (b) print(df[1:3])(ii) Delete the last row from the DataFrame.
(iii) Write Python statement to add a new column Total_Sales which is the addition of all the 4 quarter sales.
Consider the following DataFrame df and answer any four questions from (i)-(v):
rollno name UT1 UT2 UT3 UT4 1 Prerna Singh 24 24 20 22 2 Manish Arora 18 17 19 22 3 Tanish Goel 20 22 18 24 4 Falguni Jain 22 20 24 20 5 Kanika Bhatnagar 15 20 18 22 6 Ramandeep Kaur 20 15 22 24 Write down the command that will give the following output :
roll no 6 name Tanish Goel UT1 24 UT2 24 UT3 24 UT4 24 dtype : object(a) print(df.max)
(b) print(df.max())
(c) print(df.max(axis = 1))
(d) print(df.max, axis = 1)
Consider the following DataFrame df and answer any four questions from (i)-(v):
rollno name UT1 UT2 UT3 UT4 1 Prerna Singh 24 24 20 22 2 Manish Arora 18 17 19 22 3 Tanish Goel 20 22 18 24 4 Falguni Jain 22 20 24 20 5 Kanika Bhatnagar 15 20 18 22 6 Ramandeep Kaur 20 15 22 24 Which of the following statement/s will give the exact number of values in each column of the dataframe ?
(I) print(df.count())
(II) print(df.count(0))
(III) print(df.count)
(IV) print((df.count(axis = 'index')))Choose the correct option :
(a) both (I) and (II)
(b) only (II)
(c) (I), (II) and (III)
(d) (I), (II) and (IV)
Consider the following DataFrame df and answer any four questions from (i)-(v):
rollno name UT1 UT2 UT3 UT4 1 Prerna Singh 24 24 20 22 2 Manish Arora 18 17 19 22 3 Tanish Goel 20 22 18 24 4 Falguni Jain 22 20 24 20 5 Kanika Bhatnagar 15 20 18 22 6 Ramandeep Kaur 20 15 22 24 Which of the following command will display the column labels of the DataFrame ?
(a) print(df.columns())
(b) print(df.column())
(c) print(df.column)
(d) print(df.columns)