how to create frequency table in python 1

how to create frequency table in python

table = {}
total = 0 
    
for row in dataset:
	total += 1
	value = row[index]
	if values in table: 
		table[value] += 1
	else: 
		table[value] = 1

Here is what the above code is Doing:
1. We create a dictionary called table.
2. We iterate over each row in the dataset.
3. We increment the total count of rows.
4. We extract the value at the index of the column we’re interested in.
5. If the value is already in the table, we increment the count.
6. If the value is not in the table, we add it to the table and set the count to 1.

Similar Posts