Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Fetch_CSV Error With CSV File in Quandl and Google docs

Hi there,

I've been struggling with learning how to use the fetcher for a CSV file in google docs. I've tried it using the data on Quandl and Google Sheets, but I seem to get the same error for both:

KeyError: 'date' There was a runtime error on line 9.

Here's the code that I am using.

def preview(df):  
    log.info(df.head())  
    return df

def initialize(context):  
    context.investment_size = (context.portfolio.cash / 10.0)  
    context.stop_loss_pct = 0.995  
    set_symbol_lookup_date('2015-10-01')  
    fetch_csv('https://www.quandl.com/api/v3/datasets/WIKI/IOSP.csv', pre_func = preview)  
    context.stocks = symbols('AAPL')  

It seems to work using the tutorial that Quantopian recommended here, but once I replace it with Quandl or Google Sheets, it gives me the error. With Google Sheets, I use 'https://docs.google.com/spreadsheets/d/1vF5_kf0oU9tONtcPt_YOHTZOW3pIQYCugYmY0bXRQIM/edit?usp=sharing' as the URL.

Thanks in advance!

2 responses

Your csv needs to have a a field in row 1 called "date" and one called "symbol" in order for fetcher to parse correctly.

See example below:

def preview(df):  
    log.info(df)  
    return df

def initialize(context):  
    fetch_csv('https://docs.google.com/spreadsheets/d/1c1XGtl07SRgzk5Cd1JrTSGk8HaULl16EPmQE-RVHLYE/pub?output=csv', pre_func = preview)  

Thanks Ronald! Appreciate the help!