CBSE Class 12 Informatics Practices
Question 31 of 44
Data Handling using Pandas — Question 32
Back to all questions 32
Question Create the following dataframe by the name Project regarding a competition and answer the questions given below:
| Enrolment No. | Name | Class | Section | Project Name |
|---|---|---|---|---|
| 101 | Rekha | XII | B | Data Analysis |
| 102 | Divya | XII | C | Graphical Analysis |
| 103 | Geet | XII | H | Machine Learning |
| 104 | Jeet | XII | B | App Development |
(a) Insert two records with different methods.
(b) Insert a column to store grades given to their projects.
(c) Write a command to display the name and section for all.
(d) Write a command to display the records with index value 101 and 102.
(e) Insert a column after name to store the school name.
(f) Display the second and third record.
(g) Replace the name and section of Jeet to 'XI','A'.
(h) Remove the column Project Name and Section.
The DataFrame project is created as follows:
import pandas as pd
data = {'Name': ['Rekha', 'Divya', 'Geet', 'Jeet'],
'Class': ['XII', 'XII', 'XII', 'XII'],
'Section': ['B', 'C', 'H', 'B'],
'Project Name': ['Data Analysis', 'Graphical Analysis', 'Machine Learning', 'App Development']
}
Project = pd.DataFrame(data, index = [101, 102, 103, 104])
print(Project) Name Class Section Project Name
101 Rekha XII B Data Analysis
102 Divya XII C Graphical Analysis
103 Geet XII H Machine Learning
104 Jeet XII B App Development
(a)
Project.loc[105] = [105, 'Arya', 'XI', 'D', 'Web Development']
Project.loc[105] = ['Arya', 'XI', 'D', 'Web Development']
Project.at[106, 'Name'] = 'Vikram'
Project.at[106, 'Class'] = 'XI'
Project.at[106, 'Section'] = 'A'
Project.at[106, 'Project Name'] = 'AI Research' Name Class Section Project Name
101 Rekha XII B Data Analysis
102 Divya XII C Graphical Analysis
103 Geet XII H Machine Learning
104 Jeet XII B App Development
105 Arya XI D Web Development
106 Vikram XI A AI Research
(b)
Project['Grade'] = ['A', 'B+', 'C+', 'B', 'A+', 'C'] Name Class Section Project Name Grade
101 Rekha XII B Data Analysis A
102 Divya XII C Graphical Analysis B+
103 Geet XII H Machine Learning C+
104 Jeet XII B App Development B
105 Arya XI D Web Development A+
106 Vikram XI A AI Research C
(c)
print(Project[['Name', 'Section']]) Name Section
101 Rekha B
102 Divya C
103 Geet H
104 Jeet B
105 Arya D
106 Vikram A
(d)
print(Project.loc[[101, 102]]) Name Class Section Project Name Grade
101 Rekha XII B Data Analysis A
102 Divya XII C Graphical Analysis B+
(e)
Project.insert(1, 'School', ['ABC', 'PQR', 'ABC', 'PQR', 'XYZ', 'XYZ']) Name School Class Section Project Name Grade
101 Rekha ABC XII B Data Analysis A
102 Divya PQR XII C Graphical Analysis B+
103 Geet ABC XII H Machine Learning c+
104 Jeet PQR XII B App Development B
105 Arya XYZ XI D Web Development A+
106 Vikram XYZ XI A AI Research C
(f)
print(Project.iloc[1:3]) Name School Class Section Project Name Grade
102 Divya PQR XII C Graphical Analysis B+
103 Geet ABC XII H Machine Learning c+
(g)
Project.Class[104] = 'XI'
Project.Section[104] = 'A' Name School Class Section Project Name Grade
101 Rekha ABC XII B Data Analysis A
102 Divya PQR XII C Graphical Analysis B+
103 Geet ABC XII H Machine Learning c+
104 Jeet PQR XI A App Development B
105 Arya XYZ XI D Web Development A+
106 Vikram XYZ XI A AI Research C
(h)
Project = Project.drop(['Project Name', 'Section'], axis = 1) Name School Class Grade
101 Rekha ABC XII A
102 Divya PQR XII B+
103 Geet ABC XII c+
104 Jeet PQR XI B
105 Arya XYZ XI A+
106 Vikram XYZ XI C