Guest User

Untitled

a guest
Mar 30th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. print ("cursor.description: ", cursor.description)
  2. print()
  3. for row in cursor:
  4. print (row)
  5.  
  6. import pymysql.cursors
  7. import xlwt
  8.  
  9.  
  10. connection = pymysql.connect(host='localhost',user='root',password='',db='test',charset='utf8mb4',cursorclass=pymysql.cursors.DictCursor)
  11.  
  12. print ("Подключено!!!")
  13.  
  14. try:
  15. with connection.cursor() as cursor:
  16. sql="SELECT prod_name,prod_price From products"
  17. cursor.execute(sql)
  18. print ("cursor.description: ", cursor.description)
  19. print()
  20. for row in cursor:
  21. print (row)
  22.  
  23.  
  24. finally:
  25. connection.close()
  26.  
  27. from sqlalchemy import create_engine
  28. import pymysql
  29. import pandas as pd
  30.  
  31. conn = create_engine('mysql+pymysql://mysql_user:mysql_password@mysql_host/mysql_db')
  32.  
  33. df = pd.read_sql("SELECT * FROM table_name WHERE ...", conn)
  34. df.to_excel(r'/path/to/result.xlsx', index=False)
Add Comment
Please, Sign In to add comment