CBSE Class 12 Informatics Practices
Question 97 of 167
Python Pandas — I — Question 8
Back to all questions(a) df['C'] = np.NaN — This statement will add a new column 'C' to the dataframe and assign np.NaN (Not a Number) to all rows in this new column.
The updated dataframe will look like this:
A B D C
0 15 17 19 NaN
1 16 18 20 NaN
2 20 21 22 NaN
(b) df['C'] = [2, 5] — This statement will result in error because the length of the list [2, 5] does not match the number of rows in the DataFrame df.
(c) df['C'] = [12, 15, 27] — This statement will add a new column 'C' to the dataframe and assign the values from the list [12, 15, 27] to the new column. This time, all rows in the new column will be assigned a value.
The updated dataframe will look like this:
A B D C
0 15 17 19 12
1 16 18 20 15
2 20 21 22 27