Guest User

Untitled

a guest
Feb 7th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. import pandas as pd
  2. import pypyodbc
  3.  
  4. q0 = '''
  5. select *
  6. from weatherview x
  7. where x.WeatherNodeRCIKey IN (481, 562, 563, 561, 564, 565, 560, 658)
  8. and x.WeatherDate >= '01-jan-2016'
  9. '''
  10. try:
  11. con = pypyodbc.connect(driver='{Oracle in OraClient11g_home1}',
  12. server='oracle', uid='acct', pwd='Pass', dbq='table')
  13.  
  14. with con:
  15. cur = con.cursor()
  16. cur.execute(q0)
  17. q0_rows = cur.fetchall()
  18. q0_hdnm = [i[0] for i in cur.description]
  19.  
  20. except Exception as e:
  21. print("Error: " + str(e))
  22.  
  23. df0 = pd.DataFrame(q0_rows, columns=q0_hdnm)
  24. df0.head()
  25.  
  26. import pandas as pd
  27. import cx_Oracle
  28.  
  29. q0 = '''
  30. select *
  31. from weatherview_historical x
  32. where x.WeatherNodeRCIKey IN (481, 562, 563, 561, 564, 565, 560, 658)
  33. and x.WeatherDate >= '01-jan-2016'
  34. and x.WeatherTypeLu in (6436,6439)
  35. '''
  36. try:
  37. #establish connection with profit (oracle) db
  38. con = cx_Oracle.connect(user='uid', password='pass', dsn='dsn_name')
  39. df0 = pd.read_sql_query(q0, con)
  40.  
  41. except Exception as e:
  42. #return error message
  43. print("Error: " + str(e))
Add Comment
Please, Sign In to add comment