Skip to main contentSkip to solution

Consider a DataFrame 'df'. Which of the following statements are INCORRECT with respect to following operations?

(A) df['a'] = [30,40,50], will add a new column 'a' to the DataFrame 'df'.

(B) df.loc['a'] = [30,40,50], will add a new column 'a' to the DataFrame 'df'.

(C) df.['a'] = [30,40,50], will add a new row to the DataFrame 'df'.

(D) df.drop('a', axis =0) will delete the row with label 'a' from the DataFrame 'df'.

Solution

✅ Correct Option: 2

Statement (B) is incorrect because df.loc['a'] = [...] selects by row label, so it adds a new row labelled 'a', not a column.

Statement (C) is incorrect because df.['a'] is invalid syntax, and even df['a'] = [...] would add a column, not a row.


Statement (A): correct. df['a'] = [...] creates a new column 'a', provided the list length matches the number of rows.

Statement (D): correct. axis=0 means rows, so df.drop('a', axis=0) removes the row labelled 'a'. It returns a new DataFrame unless inplace=True is used.

To add a row use df.loc[label] = [...], and to add a column use df[name] = [...].

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question