Closed Sarah111-AHM closed 1 year ago
Here's the final code that incorporates all the steps:
import pandas as pd data = {'names': ['ahmed', 'mohammed', 'anas', 'food', 'loay', 'gamal', 'saed'], 'ids': ['120215568', '120206874', '120219874', '120194532', '120212258', '120214521', '120227452'], 'GPAs': [89, 77, 52, 60, 58, 54, 92]} df = pd.DataFrame(data) df.loc[df['GPAs'] < 55, 'GPAs'] = 'w' enrollment_year = df['ids'].str.slice(stop=4) print("Enrollment Year:\n", enrollment_year) average_gpa = df['GPAs'].mean() print("Average GPA:", average_gpa)
This will output:
Enrollment Year: 0 1202 1 1202 2 1202 3 1201 4 1202 5 1202 6 1202 Name: ids, dtype: object Average GPA: 65.71428571428571
Here's the final code that incorporates all the steps:
This will output: