CBSE Class 12 Informatics Practices
Question 141 of 167
Python Pandas — I — Question 31
Back to all questions 31
Question Consider the given DataFrame 'Genre' :
| No | Type | Code |
|---|---|---|
| 0 | Fiction | F |
| 1 | Non-fiction | NF |
| 2 | Drama | D |
| 3 | Poetry | P |
Write suitable Python statements for the following :
(i) Add a column called Num_Copies with the following data : [300, 290, 450, 760].
(ii) Add a new genre of type 'Folk Tale' having code as "FT" and 600 number of copies.
(iii) Rename the column 'Code' to 'Book_Code'.
(i)
Genre['Num_Copies'] = [300, 290, 450, 760](ii)
Genre = Genre.append({'Type': 'Folk Tale', 'Code': 'FT', 'Num_Copies': 600}, ignore_index=True)(iii)
Genre.rename(columns = {'Code': 'Book_Code'}, inplace = True)