I am a novice doing a course in python. My task is the following. I have a csv file (cameraData) containing several columns that looks like this:
IDnumber;Speedlimit;Speed;Date;Time
14075010;40;55;2021-09-11;11:15:31
14075010;40;54;2021-09-11;08:09:17
14075010;40;53;2021-09-11;13:02:41
14075010;40;49;2021-09-11;13:02:55
I want to compare the Speedlimit column with the Speed column. The idea is that the user can input a percentage and the program returns a list with the speeds that are x % over the speed limit. I am not allowed to use pandas. I have tried using dictreader and nested for loops to iterate through the 2 columns. I cant really figure out how to do it without pandas. I have also though about using zip() but I think it might be a bit of a workaround. I am unsure what is the best way to compare the columns(percentage wise). Here is my code so far:
import csv
#convert input to percentage decimal
percentoverspeedlimit = input("Input percentage over speed limit: ")
percentage = float(percentoverspeedlimit)
percentage_decimal = 1 + (variable / 100)
#create new function and empty dict
def speedlimitplus(camera_data):
overspeedlimit={}
#open file
with open(camera_data, 'r') as p:
csv_reader = csv.DictReader (p, delimiter = ';')
for row in csv_reader:
overspeedlimit[row['Speedlimit']] = overspeedlimit.get(row['Speedlimit'], 0) + 1
return overspeedlimit
#use function
camera_data = speedlimitplus('cameraData.csv')
print(overspeedlimit)
I have been struggling to find example code that isn´t pandas. Resources, example code or hints/tips are appreciated. Thanks.