Frequency table

Hi, I have a question regarding the code below for creating frequency table. My question is, why is the code def freq_table(column), because when I try to write it, I put def freq_table(genres) instead. I think I understand the logic of frequency table, I just didn’t understand where is the argument (column) instead of (genres). Can somebody please elaborate the logic for me please? Greatly appreciate it.

Best,
Cho

def extract(index):
    column = []    
    for row in apps_data[1:]:
        value = row[index]
        column.append(value)    
    return column

genres = extract(11)

SOLUTION CODE

def freq_table(column):
    frequency_table = {}    
    for value in column:
        if value in frequency_table:
            frequency_table[value] += 1
        else:
            frequency_table[value] = 1            
    return frequency_table

genres_ft = freq_table(genres)

Hi Cho!

It doesn´t matter WHAT you call your parameter inside the ()
as long as you use that same name inside the function. In the solution case it´s column as used inside the function: for value in column:

The name genres at the bottom:

genres_ft = freq_table(genres) uses the above created variable genres:

genres = extract(11)

and passes it to freq_table()

1 Like