Which of the statements are INCORRECT with respect to DataFrame (df) operations?
A. df['a'] = ['1','2','3','4']_____________ will add a new column 'a' in the DataFrame
B. df.loc['a'] = ['1','2','3','4']________ will add a new column 'a' to the DataFrame
C. df.drop('a', axis = 0)____________ will drop the row label 'a' from the DataFrame
D. df['a'] = ['1','2','3','4']_____________ will add a new row 'a' in the DataFrame
Which of the statements are INCORRECT with respect to DataFrame (df) operations?
A. df['a'] = ['1','2','3','4']_____________ will add a new column 'a' in the DataFrame
B. df.loc['a'] = ['1','2','3','4']________ will add a new column 'a' to the DataFrame
C. df.drop('a', axis = 0)____________ will drop the row label 'a' from the DataFrame
D. df['a'] = ['1','2','3','4']_____________ will add a new row 'a' in the DataFrame
Solution
Square brackets with a label, as in df['a'] = [...], create or overwrite a column. So A is correct and D is incorrect, because it adds a column, not a row.
df.loc['a'] = [...] selects or creates a row with index label 'a'. So B is incorrect, because it adds a row, not a column.
df.drop('a', axis = 0) removes the row labelled 'a' (axis 0 means rows), so C is correct.
Options 2, 3 and 4: these include A or C, but both are correct statements.
Memory trick: df[...] works on columns, while df.loc[...] works on rows. For drop, axis 0 means rows and axis 1 means columns.
Related questions:
2026: 13 May Shift 2
2025: 15 May Shift 2
2026: 23 May Shift 2
2025: 27 May Shift 2