Skip to content

Instantly share code, notes, and snippets.

@IanHopkinson
Created April 8, 2014 08:04
Show Gist options
  • Save IanHopkinson/10100812 to your computer and use it in GitHub Desktop.
Save IanHopkinson/10100812 to your computer and use it in GitHub Desktop.
Get Yahoo!Finance data on ScraperWiki
#!/usr/bin/env python
"""
Save stock ticker data from Yahoo! Finance to sqlite.
"""
import datetime as d
import sqlite3
import pandas.io.data as web
import pandas.io.sql as sql
# Get the data
frame = (web.DataReader('FB', # ticker symbol
'yahoo', # web service
d.datetime(2010, 3, 1), #start date
d.datetime.today())) #end date
# Wrangle the date field
frame = frame.reset_index()
frame[['Date']] = frame[['Date']].applymap(lambda x: x.isoformat())
# Write to the database
sql.write_frame(frame, 'stockdata', sqlite3.connect("scraperwiki.sqlite"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment