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 |
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)
Python Pandas
1 Like
Answer
print(df.columns)
Explanation
The statement df.columns is used to access the column labels (names) of a DataFrame in pandas.
Answered By
1 Like
Related Questions
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)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 Ms. Sharma, the class teacher wants to add a new column, the scores of Grade with the values, 'A', 'B', 'A', 'A', 'B', 'A' , to the DataFrame.
Help her choose the command to do so :
(a) df.column = ['A', 'B', 'A', 'A', 'B', 'A']
(b) df['Grade'] = ['A', 'B', 'A', 'A', 'B', 'A']
(c) df.loc['Grade'] = ['A', 'B', 'A', 'A', 'B', 'A']
(d) Both (b) and (c) are correct
Write a program that stores the sales of 5 fast moving items of a store for each month in 12 Series objects, i.e., S1 Series object stores sales of these 5 items in 1st month, S2 stores sales of these 5 items in 2nd month, and so on.
The program should display the summary sales report like this :
Total Yearly Sales, item-wise (should display sum of items' sales over the months) Maximum sales of item made : <name of item that was sold the maximum in whole year> Maximum sales for individual items Maximum sales of item 1 made : <month in which that item sold the maximum> Maximum sales of item 2 made : <month in which that item sold the maximum> Maximum sales of item 3 made : <month in which that item sold the maximum> Maximum sales of item 4 made : <month in which that item sold the maximum> Maximum sales of item 5 made : <month in which that item sold the maximum>