PythonExerciseSep18Class

py

School

Boston University *

*We aren’t endorsed by this school

Course

BA472

Subject

Computer Science

Date

Jan 9, 2024

Type

py

Pages

2

Uploaded by MagistrateHyena2457

Report
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Sep 18 08:31:15 2023 This document cannot be shared with anyone without permission @author: nobaycik """ #Save this file in Documents as PythonExerciseSep18Class.py import numpy as np import pandas as pd StudentData = pd.read_excel('/Users/shunnosuke/Desktop/BA472/StudentDataSep18.xlsx') if isinstance(StudentData, pd.DataFrame): print("It's a Pandas DataFrame") else: print("It's not a Pandas DataFrame") if isinstance(StudentData, np.ndarray): print("It's a Numpy array") else: print("It's not a Numpy array") print("\n") #Let's see the content of our data set print(StudentData) print('\n') #Let's see the first five row of our data set print(StudentData.head()) print('\n') print(len(StudentData)) #there is a "nan" in the prerequisite grade column. Let's remove that row entirely. # Drop rows with NaN values StudentData_cleaned = StudentData.dropna() print(StudentData_cleaned) print(len(StudentData_cleaned)) #convert pandas into numpy StudentData_np = StudentData_cleaned.to_numpy() # to convert an existing pandas df into a numpy array if isinstance(StudentData_np, pd.DataFrame): print("It's a Pandas DataFrame") else: print("It's not a Pandas DataFrame") if isinstance(StudentData_np, np.ndarray): print("It's a Numpy array") else: print("It's not a Numpy array") print("\n")
#Let's see the size of our data set after cleaning print("The data set has a form of") #let's find the average age of students age_col = StudentData_np[:,2].astype(float) # the "," gets all the rows for column [2] (the third column) print(age_col) average = np.mean(age_col) print(average) #find unique categories in "major" column
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help