Informatics Practices
Create a dataframe ‘Student’ from two series—Name and Grade, Name and Marks of five students.
(a) Display the first three records from student dataframe.
(b) Display the last two records from student dataframe.
Python Data Handling
1 Like
Answer
The Student DataFrame is created as :
import pandas as pd
Name = ['John', 'Anna', 'Peter', 'Linda', 'Bob']
Grade = ['A', 'B', 'A+', 'C', 'B+']
Marks = [90, 80, 95, 70, 85]
S1 = pd.Series(Grade, index = Name)
S2 = pd.Series(Marks, index = Name)
Student = pd.DataFrame({'Grade' : S1, 'Marks' : S2 })
print(Student)
Output
Grade Marks
John A 90
Anna B 80
Peter A+ 95
Linda C 70
Bob B+ 85
(a)
print(Student.head(3))
Output
Grade Marks
John A 90
Anna B 80
Peter A+ 95
(b)
print(Student.tail(2))
Output
Grade Marks
Linda C 70
Bob B+ 85
Answered By
3 Likes
Related Questions
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.
Consider the following dataframe: CORONA and answer the questions given below:
ID State Cases 100 Delhi 3000 110 Mumbai 4000 120 Chennai 5000 130 Surat 4500 Create the above-given dictionary with the given indexes.
(a) Write code to add a new column “Recovery” using the series method to store the number of patients recovered in every state.
(b) To add a new column “Deaths” using the assign() method to store the number of deaths in every state.
(c) To add a new row to store details of another state using loc (assume values).
(d) To add a new column "Percentage" using the insert() method to store the percentage of recovery in every state (assume values). The column should be added as the fourth column in the dataframe.
(e) To delete the column “Percentage” using del command.
(f) To delete the column “Deaths” using pop() method.
(g) To insert a new row of values using iloc[] at the 1st position.
(h) To delete Cases and State temporarily from the dataframe.
Create a dataframe of dictionary consisting of Name, Sub1, Sub2, Sub3, Sub4, Sub5 of five students.
(a) Display the dataframe.
(b) Display the first 5 rows and bottom 3 rows of student dataframe.
Create two dataframes of salary of five employees and do the following:
(a) Display both the dataframes.
(b) Add 5000 as bonus in both dataframes and display them.