Informatics Practices
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.
Python Data Handling
3 Likes
Answer
(a)
import pandas as pd
data = {
'Name': ['Joseph', 'Ananya', 'Praneet', 'Lakshmi', 'Bhagya'],
'Sub1': [90, 80, 95, 70, 85],
'Sub2': [85, 90, 88, 92, 89],
'Sub3': [88, 85, 90, 95, 92],
'Sub4': [92, 88, 85, 90, 95],
'Sub5': [95, 92, 92, 88, 90]
}
Student = pd.DataFrame(data)
print(Student)
Output
Name Sub1 Sub2 Sub3 Sub4 Sub5
0 Joseph 90 85 88 92 95
1 Ananya 80 90 85 88 92
2 Praneet 95 88 90 85 92
3 Lakshmi 70 92 95 90 88
4 Bhagya 85 89 92 95 90
(b)
print("First 5 rows:")
print(Student.head(5))
print("\nBottom 3 rows:")
print(Student.tail(3))
Output
First 5 rows:
Name Sub1 Sub2 Sub3 Sub4 Sub5
0 Joseph 90 85 88 92 95
1 Ananya 80 90 85 88 92
2 Praneet 95 88 90 85 92
3 Lakshmi 70 92 95 90 88
4 Bhagya 85 89 92 95 90
Bottom 3 rows:
Name Sub1 Sub2 Sub3 Sub4 Sub5
2 Praneet 95 88 90 85 92
3 Lakshmi 70 92 95 90 88
4 Bhagya 85 89 92 95 90
Answered By
2 Likes
Related Questions
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 ‘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.
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.
Create a dataframe using list [10, 11, 12, 13, 14] [23, 34, 45, 32, 65] [55, 60, 65, 70, 75] and do the following:
(a) Display the dataframe.
(b) Add the list [1, 2, 3, 4, 5] to dataframe and display it.