Advertisement
Guest User

Untitled

a guest
Apr 18th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import psycopg2
  2. import pandas as pd
  3.  
  4.  
  5. def getRemoteConn():
  6. # set username and password
  7. username = 'your@emailaddress.com'
  8. password = 'supersecretpassword'
  9. # set up database, typically account.game, the demo game should work for every user
  10. database = 'demo-account.demo-game'
  11. # connect and give back the connection
  12. conn = psycopg2.connect(
  13. "dbname='{db}' user='{user}' host='data.deltadna.net' password='{passw}'".format(user=username,
  14. passw=password,
  15. db=database))
  16. return conn
  17.  
  18.  
  19. if __name__ == '__main__':
  20. try:
  21. # run the query using the returned connection
  22. data_frame = pd.read_sql_query(
  23. 'select userId, sessionId, eventName, eventTimestamp, eventDate from events_dev limit 500',
  24. con=getRemoteConn())
  25. # do something with the dataframe created by pandas
  26. print data_frame.describe()
  27. except psycopg2.OperationalError as e:
  28. # catch database exception and print its message
  29. print e.message
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement