Advertisement
willbr2k

conexao_matriz

Jan 14th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #pip install mysql-connector-python
  2. #https://stackoverflow.com/questions/53077133/market-basket-analysis-in-python-for-large-transaction-dataset
  3. import mysql.connector
  4. import numpy as np
  5. from mysql.connector import errorcode
  6.  
  7.  
  8. try:
  9. cnx = mysql.connector.connect(user='root', password='p@ssw0rd',
  10. host='localhost',
  11. port='3307',
  12. database='sice')
  13.  
  14. cursor_documentos = cnx.cursor(buffered=True)
  15. query_documentos = ("SELECT documento FROM vendaarquivo WHERE data='{}'".format("2016-06-23"))
  16. cursor_documentos.execute(query_documentos)
  17.  
  18. cursor_itens = cnx.cursor()
  19.  
  20. dataset = []
  21. i = 0
  22.  
  23. for x in cursor_documentos:
  24. query_itens = "select codigo from vendaarquivo where documento='{}'".format(x[0])
  25. cursor_itens.execute(query_itens)
  26. y = cursor_itens.fetchall()
  27. for z in zip(*y):
  28. dataset.insert(i, z)
  29. i += 1
  30.  
  31. #print(dataset)
  32. print(dataset[0][0])
  33. cursor_documentos.close()
  34. cursor_itens.close()
  35.  
  36. except mysql.connector.Error as err:
  37.  
  38. if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
  39. print("Something is wrong with your user name or password")
  40. elif err.errno == errorcode.ER_BAD_DB_ERROR:
  41. print("Database does not exist")
  42. else:
  43. print(err)
  44. else:
  45. cnx.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement