pandas - How to write data to Redshift that is a result of a dataframe created in Python? -


i have dataframe in python. can write data redshift new table? have created db connection redshift , able execute simple sql queries. need write dataframe it.

you can use to_sql push data redshift database. i've been able using connection database through sqlalchemy engine. sure set index = false in to_sql call. table created if doesn't exist, , can specify if want call replace table, append table, or fail if table exists.

from sqlalchemy import create_engine import pandas pd  conn = create_engine('postgresql://username:password@yoururl.com:5439/yourdatabase')  df = pd.dataframe([{'a': 'foo', 'b': 'green', 'c': 11},{'a':'bar', 'b':'blue', 'c': 20}])  df.to_sql('your_table', conn, index = false, if_exists = 'replace') 

note may need pip install psycopg2 in order connect redshift through sqlalchemy.

to_sql documentation


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -