I am trying to find the most common value located within a column in a CSV file, and return that value.
I am only allowed to import the file that I'm using.
I cannot use pandas.
Here is what I tried to do:
def get_longest_value_from_col(filename, column_name):
with open(filename, 'r') as csvfile:
reader = csv.DictReader(csvfile)
counts = {}
num = filename(column_name)
for i in filename:
curr_frequency = filename.count(i)
if curr_frequency > counter:
counter = curr_frequency
num = i
return num
print(str(
get_longest_value_from_col(
filename='personal_data.csv',
column_name='the_location'
)
))