Task2 - Colaboratory Dip
Task2 - Colaboratory Dip
Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount("/content/drive", force_remount=True).
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df = pd.read_csv('student_data.csv')
df
https://colab.research.google.com/drive/1wzL6YRktB5jGWEQR6OVWwjDfjlzygVG3#scrollTo=VrKhRQAXPSAX&printMode=true 1/3
9/30/23, 11:40 PM Task2 - Colaboratory
Task 3: Count the number of students by 'Major' and create a bar plot
# Calculate the average 'GPA' for each 'Major' and display as a DataFrame
print("\nTask 4: Calculate the average 'GPA' for each 'Major'")
major_gpa_avg = df.groupby('Major')['GPA'].mean().reset_index()
print(major_gpa_avg)
# Create a new DataFrame with students having 'GPA' > 3.5 and 'Age' < 25
print("\nTask 5: Create a new DataFrame with 'GPA' > 3.5 and 'Age' < 25")
filtered_df = df[(df['GPA'] > 3.5) & (df['Age'] < 25)]
print(filtered_df)
output Task 5: Create a new DataFrame with 'GPA' > 3.5 and 'Age' < 25
StudentID Name Age GPA Major
24 25 Student 25 20 3.525940 Science
37 38 Student 38 23 3.865368 Science
40 41 Student 41 20 3.887455 Science
45 46 Student 46 23 3.829072 Business
47 48 Student 48 23 3.823113 Engineering
54 55 Student 55 23 3.573453 Science
57 58 Student 58 23 3.957774 Science
62 63 Student 63 23 3.634259 Business
70 71 Student 71 20 3.691028 Science
77 78 Student 78 24 3.780056 Business
85 86 Student 86 20 3.714173 Business
87 88 Student 88 18 3.944086 Engineering
88 89 Student 89 22 3.857096 Engineering
91 92 Student 92 20 3.809201 Business
94 95 Student 95 19 3.569902 Science
95 96 Student 96 20 3.795674 Business
https://colab.research.google.com/drive/1wzL6YRktB5jGWEQR6OVWwjDfjlzygVG3#scrollTo=VrKhRQAXPSAX&printMode=true 2/3
9/30/23, 11:40 PM Task2 - Colaboratory
https://colab.research.google.com/drive/1wzL6YRktB5jGWEQR6OVWwjDfjlzygVG3#scrollTo=VrKhRQAXPSAX&printMode=true 3/3