Advertisement
AndreVLG

postgres_connect_py

Nov 13th, 2019
602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. arguments = {'user': 'postgres',
  2.              'pwd': 'password',
  3.              'host': 'localhost',
  4.              'port': 5432,
  5.              'db': 'db_name'}  
  6. connection_string = 'postgresql://{}:{}@{}:{}/{}'.format(arguments['user'],
  7.                                                          arguments['pwd'],
  8.                                                          arguments['host'],
  9.                                                          arguments['port'],
  10.                                                          arguments['db'])
  11.  
  12. engine = create_engine(connection_string)
  13. query = ''' SELECT *
  14.                FROM bd_table
  15.            '''
  16. df = pd.io.sql.read_sql(query, con = engine, index_col = 'id')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement