KnowledgeBoat Logo
|

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