Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # http://stackoverflow.com/questions/1466741/parameterized-queries-with-psycopg2-python-db-api-and-postgresql
- import psycopg2
- import pandas.io.sql as sqlio
- username = 'yomama'
- pwd = 'yopwd'
- conn = psycopg2.connect("host='your_host' dbname='mydb' user=" + username + " password=" + pwd)
- sql = "select * from medicine_journal where medication = '%(medicine)s'"
- df = sqlio.read_frame(sql % {'medicine':'flonase'}, conn) # Create a dataframe that consists of the data defined by our SQL
- conn.close() # We've created our dataframe, so we can discard our connection now...
- print df.to_string()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement