Advertisement
Guest User

Untitled

a guest
May 21st, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. database = mysql.connect(user='erel17', # STUDENT_ID
  2. passwd='SHwLUTtghp5C', # Losenord
  3. database='erel17', # STUDENT_ID
  4. host='blu-ray.student.bth.se')
  5. c = database.cursor(dictionary=True)
  6.  
  7.  
  8. c.execute("select distinct gender from Product")
  9. record = c.fetchall()
  10. print("Total number of rows in python_developers is - ", c.rowcount)
  11. for row in record:
  12. print(row['gender'])
  13.  
  14. print("hej på dig")
  15. ## Hämtar vi könen som finns
  16. df = pd.read_csv(cmd_folder + 'data/Products.csv')
  17. genders = [record[0]['gender'],record[1]['gender']]
  18. types = [
  19. df[(df['gender'] == genders[0])]['type'].unique().tolist(),
  20. df[(df['gender'] == genders[1])]['type'].unique().tolist()
  21. ]
  22.  
  23. c.execute("select ProductCategoryName from Product join ProductType on Product.ProductTypeId = ProductType.ProductTypeId join ProductCategory on ProductType.ProductCategoryId = ProductCategory.ProductCategoryId where gender = 'female' group by ProductCategoryName")
  24. recordFemale = c.fetchall()
  25. c.execute("select ProductCategoryName from Product join ProductType on Product.ProductTypeId = ProductType.ProductTypeId join ProductCategory on ProductType.ProductCategoryId = ProductCategory.ProductCategoryId where gender = 'Male' group by ProductCategoryName")
  26. recordMale = c.fetchall()
  27.  
  28. for row in recordFemale:
  29. print(row['ProductCategoryName'])
  30.  
  31. children = [[{
  32. 'url': '',
  33. 'name': row['ProductCategoryName']
  34. } for row in recordFemale], [{
  35. 'url': '',
  36. 'name': row['ProductCategoryName']
  37. } for row in recordMale]]
  38. ''' SQL '''
  39.  
  40. result = [{
  41. 'title': genders[0],
  42. 'children': children[0]
  43. }, {
  44. 'title': genders[1],
  45. 'children': children[1]
  46. }]
  47. return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement