Advertisement
Guest User

Untitled

a guest
Jul 8th, 2018
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. import mysql.connector
  2. conn=mysql.connector.connect(user='jump',password='secret',host='localhost',database='accidents')
  3. cursor=conn.cursor()
  4. cursor.execute("SELECT vtype FROM vehicle_type WHERE vtype LIKE '%otorcycle%';")
  5. cycleList = cursor.fetchall()
  6. selectSQL = ('''
  7. SELECT t.vtype, a.accident_severity
  8. FROM accidents_2016 AS a
  9. JOIN vehicles_2016 AS v ON a.accident_index = v.accident_index
  10. JOIN vehicle_type AS t ON v.vehicle_type = t.vcode
  11. WHERE t.vtype LIKE '%otorcycle%'
  12. ORDER BY a.accident_severity;''')
  13. insertSQL = ("INSERT INTO accident_medians VALUES (%s, %s);")
  14.  
  15. for cycle in cycleList:
  16. cursor.execute(selectSQL, (cycle[0],))
  17. accidents = cursor.fetchall()
  18. quotient, remainder = divmod(len(accidents),2)
  19. if remainder:
  20. med_sev = accidents[quotient][1]
  21. else:
  22. med_sev = (accidents[quotient][1] + accidents[quotient+2][1])/2
  23. print('Finding median for',cycle[0])
  24. cursor.execute(insertSQL,(cycle[0],med_sev))
  25. conn.commit()
  26. conn.close()
  27.  
  28.  
  29.  
  30. #This yields the following errors:
  31. Traceback (most recent call last):
  32. File "\\CATTERY-DC1\UserData\Macavity\Desktop\final script.py", line 16, in <module>
  33. cursor.execute(selectSQL, cycle[0])
  34. File "C:\Users\Macavity\AppData\Local\Programs\Python\Python36\lib\site-packages\mysql\connector\cursor_cext.py", line 246, in execute
  35. prepared = self._cnx.prepare_for_mysql(params)
  36. File "C:\Users\Macavity\AppData\Local\Programs\Python\Python36\lib\site-packages\mysql\connector\connection_cext.py", line 520, in prepare_for_mysql
  37. raise ValueError("Could not process parameters")
  38. ValueError: Could not process parameters
  39. >>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement