Order Statistics: Example using Python

The example below illustrates how to apply order statistics to a column in excel.

Order Statistics are basically to find the minimum, maximum and range of an array or set of data.

The program assumes that the 2nd column of the "details" worksheet in "marks.xls" workbook has marks obtained in Math by the students of a class.

-----------
from openpyxl import load_workbook
import numpy as np

# File being read is marks.xlsx
wb = load_workbook(filename = 'marks.xlsx')

sheet = wb['details']

# Finding no of rows and columns in the sheet
rows = sheet.max_row
columns = sheet.max_column

matharr = np.ndarray(rows-1)

# reading the values of a column to numpy array to be able to compute order statistics
for i in range(2, rows+1):
    matharr[i-2] = sheet.cell(row = i, column = 2).value

print("Minimum of the array")
print(np.amin(matharr))
print("Minimum of the array excluding NaN (Not a Number) values")
print(np.nanmin(matharr))
print("maximum of the array") print(np.amax(matharr))
print("maximum of the array excluding NaN (Not a Number) values")print(np.nanmax(matharr))

print("Range of values (maximum - minimum)")
print(np.ptp(matharr))

Comments

Popular posts from this blog

Santa Clara (CA) DMV - Driving Test Practice Routes

Installing Python Packages on Mac OS X using Conda

Trip to Coorg from Bangalore