Skip to content

Commit

Permalink
fix: Grouped Frequency Last Row Keep Append Even Though 0 Frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
brotherzhafif committed Oct 13, 2024
1 parent cb20062 commit e012ff0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 49 deletions.
5 changes: 3 additions & 2 deletions FrequencyTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,13 @@ def PopulateGrouped(self):
mode = []

# Initiating Used Parameter for Frequency Table
old_number = 0
interval = self.interval
current_number = self.base - 1
old_number = 0
current_top_cumulative_frequency = 1

# Processing the Frequency Table Data
while current_number <= self.top - 3:
while current_top_cumulative_frequency != 0:
# Finding Class Lowest Value
old_number = current_number + 1
bottom.append(old_number)
Expand Down
91 changes: 44 additions & 47 deletions Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,70 +5,67 @@

# Raw Data
dataset = [
'Mango', 'Pineapple', 'Banana', 'Banana', 'Pineapple', 'Banana',
'Banana', 'Grapes', 'Pear', 'Pineapple', 'Orange', 'Strawberry',
'Orange', 'Mango', 'Banana', 'Pineapple', 'Orange', 'Banana',
'Strawberry', 'Pear', 'Apple', 'Banana', 'Pineapple', 'Orange',
'Mango', 'Apple', 'Pear', 'Pear', 'Pear', 'Grapes', 'Pear',
'Orange', 'Grapes', 'Strawberry', 'Mango', 'Orange', 'Orange',
'Mango', 'Pear', 'Strawberry', 'Pear', 'Orange', 'Mango',
'Mango', 'Pear', 'Grapes', 'Apple', 'Mango', 'Pineapple',
'Strawberry', 'Strawberry', 'Grapes', 'Apple', 'Banana',
'Grapes', 'Banana', 'Strawberry', 'Mango', 'Strawberry',
'Orange', 'Pear', 'Grapes', 'Orange', 'Apple'
12.5, 12.5, 12.1, 12.6, 12.7, 12.5, 43.2, 43.2, 43.2, 43.5,
34.2, 34.1, 34.3, 34.2, 34.0, 34.5, 56.7, 56.8, 56.5, 56.6,
56.9, 57.0, 67.9, 67.8, 67.5, 67.6, 67.7, 78.4, 78.1, 78.3,
78.2, 78.9, 78.8, 89.0, 89.1, 89.2, 90.5, 91.2, 90.3, 90.0,
98.3, 98.1, 98.0, 99.5, 99.4, 99.6, 99.1, 99.2, 99.3, 99.0,
22.4, 22.3, 22.5, 22.2, 22.1, 22.0, 25.4, 25.5, 25.6, 25.0,
32.4, 32.5, 32.3, 32.2, 32.1, 32.0, 45.6, 45.5, 45.4, 45.0,
56.3, 56.4, 56.2, 56.1, 56.0, 60.5, 64.0, 64.1, 64.2, 64.3,
71.3, 71.4, 71.5, 71.6, 71.7, 71.8, 84.2, 84.3, 84.1, 84.0,
12.9, 12.8, 12.7, 12.6, 12.5, 12.4
]


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

# Processing Raw Data to Frequency Grouped Frequency Table
# data.PopulateGrouped() # Grouped Data
data.PopulateSimple() # Simple Data
data.PopulateGrouped() # Grouped Data
# data.PopulateSimple() # Simple Data

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

# "C <" : data.grouped.bottom_limit,
# "CF <" : data.grouped.bottom_cumulative_frequency,
# "C >" : data.grouped.top_limit,
# "CF >" : data.grouped.top_cumulative_frequency,
# "Relative Frequency" : data.grouped.percentage_relative_frequency
# }
# )

# Simple Populated Data
dfs = pd.DataFrame(
dfg = pd.DataFrame(
{
"Class" : data.simple.classval,
"Frequency" : data.simple.frequency,
"Relative Frequency" : data.simple.percentage_relative_frequency
"Class Interval" : data.grouped.ranges,
"Class Limit" : data.grouped.limit,
"Frequency" : data.grouped.frequency,
"Midpoint" : data.grouped.midpoint,

"C <" : data.grouped.bottom_limit,
"CF <" : data.grouped.bottom_cumulative_frequency,
"C >" : data.grouped.top_limit,
"CF >" : data.grouped.top_cumulative_frequency,
"Relative Frequency" : data.grouped.percentage_relative_frequency
}
)

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

# tablegrouped = tabulate.tabulate(
# dfg,
# headers='keys',
# tablefmt='pipe',
# Simple Populated Data
# dfs = pd.DataFrame(
# {
# "Class" : data.simple.classval,
# "Frequency" : data.simple.frequency,
# "Relative Frequency" : data.simple.percentage_relative_frequency
# }
# )

# Print The Processed Data
print(tablesimple)
# print(tablegrouped)
# Converting Pandas Data Into Tabulate
# tablesimple = tabulate.tabulate(
# dfs,
# headers='keys',
# tablefmt='pipe'
# )

tablegrouped = tabulate.tabulate(
dfg,
headers='keys',
tablefmt='pipe',
)

# Print The Processed Data
# print(tablesimple)
print(tablegrouped)

0 comments on commit e012ff0

Please sign in to comment.