#This code utilizes pandas which is a way for you as a user, to create data tables that are much more organized
#imports pandas so it's able to be used
import pandas as pd
#data is created and will be sorted from left to right into top to bottom
data = {'Name': ['Matthew', 'Lindsey', 'Josh', 'Ethan'],
'Grade': [97, 92, 90, 80]}
#defines a variable and utilizes pandas by using a DataFrame for the data
df = pd.DataFrame(data)
#increase the side count by one
df.index += 1
print(df)
Name Grade
0 Alice 85
1 Bob 92
2 Charlie 78
#imports numpy and defines it as np for ease
import numpy as np
#creates a list of values similar to python lists
grades = np.array([85, 92, 78, 90, 88])
# Calculates the mean grade using np.mean
mean_grade = np.mean(grades)
print("Mean Grade:", mean_grade)
Mean Grade: 86.6
Homework Hack 1
Create a code that makes a data table which organizes the average values(mean) from a data set the has atleast 5 values per category ex:
import pandas as pd
import numpy as np
# Sample data
data = {
'Grade': ['A', 'B', 'A', 'C', 'B', 'C', 'A', 'B', 'A'],
'Percent': [94, 82, 91, 76, 89, 79, 92, 87, 99]
}
# Create a Pandas DataFrame
df = pd.DataFrame(data)
# Calculate the mean of each Grade using NumPy
means = df.groupby('Grade')['Percent'].mean().reset_index()
# Organize the results into a new data table
result = pd.DataFrame({'Grade': ['A', 'B', 'C'], 'Mean Grade': means['Percent']})
# Display the result
print(result)
Grade Mean Grade
0 A 94.0
1 B 86.0
2 C 77.5