Informatics Practices

Create the following dataframe by the name Project regarding a competition and answer the questions given below:

Enrolment No.NameClassSectionProject Name
101RekhaXIIBData Analysis
102DivyaXIICGraphical Analysis
103GeetXIIHMachine Learning
104JeetXIIBApp 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.

Python Data Handling

4 Likes

Answer

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)
Output
      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'
Output
       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']
Output
       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']])
Output
       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]])
Output
      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'])
Output
       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])
Output
      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'
Output
       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)
Output
       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

Answered By

4 Likes


Related Questions