KnowledgeBoat Logo
|

Informatics Practices

Consider the given DataFrame 'Genre' :

NoTypeCode
0FictionF
1Non-fictionNF
2DramaD
3PoetryP

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'.

Python Pandas

8 Likes

Answer

(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)

Answered By

3 Likes


Related Questions