Informatics Practices

Consider the following DataFrame df and answer any four questions from (i)-(v):

rollnonameUT1UT2UT3UT4
1Prerna Singh24242022
2Manish Arora18171922
3Tanish Goel20221824
4Falguni Jain22202420
5Kanika Bhatnagar15201822
6Ramandeep Kaur20152224

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

Python Pandas

2 Likes

Answer

df['Grade'] = ['A', 'B', 'A', 'A', 'B', 'A']

Explanation

The statement df['Grade'] specifies that we are creating a new column named 'Grade' in the DataFrame df. The square brackets [] are used to access or create a column in a DataFrame.

Answered By

3 Likes


Related Questions