A DataFrame ResultDF is created below:
Arnab Ramit Samridhi Riya Mallika Maths 90 92 89 81 94 Science 91 81 91 71 95 Hindi 97 96 88 67 99 Hindi 97 89 78 60 45
Identify the correct command to remove the duplicate row labelled ‘Hindi’.
A DataFrame ResultDF is created below:
| Arnab | Ramit | Samridhi | Riya | Mallika | |
|---|---|---|---|---|---|
| Maths | 90 | 92 | 89 | 81 | 94 |
| Science | 91 | 81 | 91 | 71 | 95 |
| Hindi | 97 | 96 | 88 | 67 | 99 |
| Hindi | 97 | 89 | 78 | 60 | 45 |
Identify the correct command to remove the duplicate row labelled ‘Hindi’.
Solution
In pandas, DataFrame.drop(labels, axis=0) removes rows by their index label. Here 'Hindi' is a row label, so ResultDF.drop('Hindi', axis=0) is the correct command.
Note that drop removes every row with that label, so both 'Hindi' rows are deleted, not just the duplicate.
Option 1: axis=1 refers to columns, and there is no column named 'Hindi', so it raises a KeyError.
Options 2 and 4: drop.Hindi and deleteduplicates.Hindi are not valid pandas syntax. The real duplicate-removal method is drop_duplicates(), and it is called with brackets.
Related questions:
2026: 26 May Shift 1
2025: 20 May Shift 1
2025: 22 May Shift 1