Get Amazon RDS (PostgreSQL) data using SQL with pandas

problem

I want to work with data in Pandas, so I use the pandas method read_sql I want to get it from Amazon RDS (PostgreSQL).

solution

Installation

Insert sqlalchemy, padas

pip install -U sqlalchemy pandas

Sample code

import sqlalchemy 
import pandas

## DB Connection configuration
username = "USERNAME"
password = "PASSWORD"
endpoint = "ENDPOINT"  # something like amazonaws.com:5432
dbname   = "DBNAME"

## Connect to Db
con = sqlalchemy.create_engine("postgresql://%s:%s@%s/%s" % (username, password, endpoint, dbname))


## Get Data
data = pandas.read_sql("YOUR_SQL", con)
print(data)

Recommended Posts

Get Amazon RDS (PostgreSQL) data using SQL with pandas
Get Amazon data using Keep API # 1 Get data
[Note] Get data from PostgreSQL with Python
Data visualization with pandas
Data manipulation with Pandas!
Shuffle data with pandas
Process csv data with python (count processing using pandas)
Get Youtube data with python
Data analysis using python pandas
Data processing tips with Pandas
Try to get data while port forwarding to RDS with anaconda.
Get Salesforce data using REST API
Data visualization method using matplotlib (+ pandas) (5)
[Python] Get economic data with DataReader
Versatile data plotting with pandas + matplotlib
Parsing CSV format data using SQL
Data visualization method using matplotlib (+ pandas) (3)
Get data from Twitter using Tweepy
Manage your data with AWS RDS
Data visualization method using matplotlib (+ pandas) (4)
Subtitle data created with Amazon Transcribe
I get an error with import pandas.
I tried using Amazon SQS with django-celery
Retrieving food data with Amazon API (Python)
Get data from Cloudant with Bluemix flask
Get Youtube data in Python using Youtube Data API
Try converting to tidy data with pandas
RDS data via stepping stones in Pandas
Overwrite data in RDS with AWS Glue
Get data from an oscilloscope with pyVISA
Execute SQL with Django + Postgresql (including PreparedStatement)
Working with 3D data structures in pandas
Example of efficient data processing with PANDAS
Best practices for messing with data with pandas
Execute raw SQL using python data source with redash and display the result
[In-Database Python Analysis Tutorial with SQL Server 2017] Step 2: Import data to SQL Server using PowerShell
I tried to make a function to retrieve data from database column by column using sql with sqlite3 of python [sqlite3, sql, pandas]
Try to aggregate doujin music data with pandas
Read Python csv data with Pandas ⇒ Graph with Matplotlib
[Python] Get all comments using Youtube Data API
[Django] How to get data by specifying SQL.
Get stock price data with Quandl API [Python]
I tried to get CloudWatch data with Python
Implement "Data Visualization Design # 3" with pandas and matplotlib
[Pandas] Basics of processing date data using dt
Interactively visualize data with TreasureData, Pandas and Jupyter.
100 language processing knock-20 (using pandas): reading JSON data
How to get article data using Qiita API
Make holiday data into a data frame with pandas
100 language processing knock-95 (using pandas): Rating with WordSimilarity-353
I tried DBM with Pylearn 2 using artificial data
[In-Database Python Analysis Tutorial with SQL Server 2017] Step 4: Feature extraction of data using T-SQL