In [1]:
## Python packages - you may have to pip install sqlalchemy, sqlalchemy_utils, and psycopg2.
from sqlalchemy import create_engine
from sqlalchemy_utils import database_exists, create_database
import psycopg2
import pandas as pd

In [2]:
#In Python: Define a database name (we're using a dataset on births, so I call it 
# birth_db), and your username for your computer (CHANGE IT BELOW). 
dbname = 'autism-docs'
username = 'rangel'

In [3]:
## 'engine' is a connection to a database
## Here, we're using postgres, but sqlalchemy can connect to other things too.
engine = create_engine('postgres://%s@localhost/%s'%(username,dbname))
print (engine.url)


postgres://rangel@localhost/autism-docs

In [5]:
## Now try the same queries, but in python!

# connect:
con = None
con = psycopg2.connect(database = dbname, user = username)

# query:
sql_query = """
SELECT * FROM \"articles-n-forums-posts\";
"""
query = pd.read_sql_query(sql_query,con)

query.tail()


Out[5]:
post id category href source text title user id tokens text_short
3773 3773 forums http://www.reddit.com/r/autism/comments/mbq4k/... http://www.reditt.com I've been aware that I have Asperger's for abo... Should I give up my writing goals? (Asperger's... 1004.0 ['should', 'i', 'give', 'up', 'my', 'writing',... I've been aware that I have Asperger's for abo...
3774 3774 forums http://www.reddit.com/r/autism/comments/m89b8/... http://www.reditt.com Recently I came across Wyndham autism friendly... Autistic friendly family vacation areas? 984.0 ['autistic', 'friendly', 'family', 'vacation',... Recently I came across Wyndham autism friendly...
3775 3775 forums http://www.reddit.com/r/autism/comments/lz53j/... http://www.reditt.com I was informed yesterday that two autistic adu... How do I manage autistic employees? 1005.0 ['how', 'do', 'i', 'manage', 'autistic', 'empl... I was informed yesterday that two autistic adu...
3776 3776 forums http://www.reddit.com/r/autism/comments/lxn3g/... http://www.reditt.com I am a student at Bicton College, Devon carryi... Equine Assisted Therapy for Autistic Adults 1006.0 ['equine', 'assisted', 'therapy', 'for', 'auti... I am a student at Bicton College, Devon carryi...
3777 3777 forums http://www.reddit.com/r/autism/comments/lwwfy/... http://www.reditt.com Hi everyone. I just found this sub-Reddit aft... 36 month old only partially showing signs of a... 1007.0 ['36', 'month', 'old', 'only', 'partially', 's... Hi everyone. I just found this sub-Reddit aft...

In [ ]: