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'.
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
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] = [...].
Related questions:
2026: 26 May Shift 1
2026: 23 May Shift 1
2026: 11 May Shift 2
2026: 23 May Shift 2