Skip to content

Commit

Permalink
Adding Example Code Tranforming Processed Data into Frequency Table w…
Browse files Browse the repository at this point in the history
…ith Pandas and Tabulate
  • Loading branch information
brotherzhafif committed Oct 12, 2024
1 parent d6c3ca4 commit 8166e8a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
4 changes: 2 additions & 2 deletions FrequencyTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def Populate(self):


# Append Processed Data into Data Attributes
self.data = ProcessedData(bottom, top, bottom_limit, top_limit, frequency, data_range, data_limit, data_midpoint, bot_cumulative_frequency, top_cumulative_frequency, relative_frequency)
self.final = ProcessedData(bottom, top, bottom_limit, top_limit, frequency, data_range, data_limit, data_midpoint, bot_cumulative_frequency, top_cumulative_frequency, relative_frequency)

# Base 5 Rounding
def roundy(self, x, base = 5):
Expand Down Expand Up @@ -124,4 +124,4 @@ def __init__(self, bot, top, bot_L, top_L, F, R, L, M, bot_CF, top_CF, RF):
self.bottom_cumulative_frequency = bot_CF
self.top_cumulative_frequency = top_CF
self.relative_frequency = RF


43 changes: 36 additions & 7 deletions Main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# EXAMPLE PROGRAM
import FrequencyTable as ft
import pandas as pd
import tabulate as tabulate

# Raw Data
data = (
dataset = (
58, 67, 45, 89, 72, 60, 76, 93,
55, 48, 62, 85, 79, 56, 41, 90,
77, 54, 68, 82, 46, 73, 57, 92,
Expand All @@ -11,12 +13,39 @@
83, 70, 44, 61, 75, 80, 71, 63, 47,51)

# Initiate Object From The Raw Data
table = ft.FrequencyTable(data)
data = ft.FrequencyTable(dataset)

# Processing Raw Data to Frequency Table
table.Populate()
data.Populate()

# Adding Percent Symbol into The Relative Frequency Coloumn
relative_frequency_with_percentage = [
f"{rf * 1:.2f}%" for rf in data.final.relative_frequency
]

# Transform The Data To A Frequency Table
# Initiating The Data Using Pandas
df = pd.DataFrame(
{
"Class Interval" : data.final.ranges,
"Class Limit" : data.final.limit,
"Frequency" : data.final.frequency,
"Midpoint" : data.final.midpoint,

"C <" : data.final.bottom_limit,
"CF <" : data.final.bottom_cumulative_frequency,
"C >" : data.final.top_cumulative_frequency,
"CF >" : data.final.top_cumulative_frequency,
"Relative Frequency" : relative_frequency_with_percentage
}
)

# Converting Pandas Data Into Tabulate
table = tabulate.tabulate(
df,
headers='keys',
tablefmt='pipe'
)

print(table)

# Print The Data
print(table.data.ranges)
print(table.data.frequency)
print(table.data.relative_frequency)
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@

pip install numpy

- Tabulate

pip install tabulate

- Pandas

pip install pandas

### Structure
- Program Structure

Expand Down

0 comments on commit 8166e8a

Please sign in to comment.