Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
3.0k views
in Information Technology by (72.8k points)
closed by

Consider the given DataFrame ‘Genre’:

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

1 Answer

+1 vote
by (62.5k points)
selected by
 
Best answer
i. Genre["Num_Copies"]=[300,290,450,760]
ii. Genre.loc[4]=["Folk Tale","FT",600]
iii.Genre=Genre.rename({"Code":"Book_Code"}, axis=1)

OR

Genre=Genre.rename({"Code":"Book_Code"}, axis="columns")

Related questions

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...