-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathretrieving_data.py
More file actions
32 lines (25 loc) · 863 Bytes
/
retrieving_data.py
File metadata and controls
32 lines (25 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/python
# -*- coding: utf-8 -*-
# retrieving_data.py
import pymysql
pymysql.install_as_MySQLdb()
import pandas as pd
import MySQLdb as mdb
if __name__ == "__main__":
# Connect to the MySQL instance
db_host = 'hostname'
db_user = 'username'
db_pass = 'password'
db_name = 'database'
con = mdb.connect(db_host, db_user, db_pass, db_name)
# Select all of the historic Google adjusted close data
sql = """SELECT dp.price_date, dp.adj_close_price
FROM symbol AS sym
INNER JOIN daily_price AS dp
ON dp.symbol_id = sym.id
WHERE sym.ticker = 'GOOG'
ORDER BY dp.price_date ASC;"""
# Create a pandas dataframe from the SQL query
goog = pd.read_sql_query(sql, con=con, index_col='price_date')
# Output the dataframe tail
print(goog.tail())