[python][redshift]用python获取redshift中的数据

https://www.blendo.co/blog/access-your-data-in-amazon-redshift-and-postgresql-with-python-and-r/

import psycopg2
import numpy as np
import pandas as pd
hostname=xxxxx
pw=xxxxx
con=psycopg2.connect(dbname='dynamicpop', host=hostname,port='15439', user='root', password=pw)
#con=psycopg2.connect(dbname='dynamicpop', host='localhost',port= '15439', user= 'root', password=pw)
cur = con.cursor()
cur.execute("SELECT * FROM analysis_190722_automation.t_time;")
a=cur.fetchall()
data_all = np.array(a)
df = pandas.DataFrame(a,index=['row1', 'row2'],columns=['col1', 'col2', 'col3'])

cur.close() 
con.close()

你可能感兴趣的:(python)