Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
fetch_csv and passing loaded .csv data to def handle_data(context, data):

Ok so I am loading external data from a .csv I have hosted on google drive. I can achieve this with the following:

from pytz import timezone  
import pandas

 # Preview the inported data frame  
def preview(df):  
    log.info(df.head())  
    return df

def initialize(context):  
    # Robinhood settings  
    set_long_only()  
    set_commission(commission.PerShare(cost=0, min_trade_cost=0))  
    context.allocation = 0.95 # Robinhood requires either limit orders or a 5% margin on orders.  
    # Fetch CSV from external source  
    fetch_csv('https://docs.google.com/spreadsheets/d/1EoT-AXs4wY88_kEsOkaYVX1KCpnovu4FwUZC1FTw9DQ/pub?gid=262287766&single=true&output=csv',  pre_func = preview, usecols=['signal'], date_column = 'Date', symbol='signal')  
    # Set Symbol to buy  
    context.security = symbol('UPRO')  

when I use the pre_func I get this output:
1969-12-31 18:00 preview:6 INFO Date signal 0 1/29/1993 0 1 2/1/1993 0 2 2/2/1993 0 3 2/3/1993 0 4 2/4/1993 0 This backtest didn't generate any logs.

So success.

Next when I move to actually make trading logic or anything from the loaded .csv. I am struggling to read the data.
I am new to this but I see that I need to use:
def handle_data(context, data):

Then I wish to view my loaded data from the .csv. I am trying to:
def handle_data(context, data): signal_data = data['signal'] print(signal_data) Shouldnt this print my signal column from my loaded .csv?

In the load_csv command I listed symbol as 'signal'

What am I missing here? Or why does it now show for me?

The reason I want to load my signal column is that I make everything in R from external data. I simply want to read the signal column and if signal == 1, then buy next market open. So hit a wall with it not being able to read the signal column in the next steps, any ideas appreciated!

EDIT***

Ok so i made sure my data was current with todays date. The print function did work however, it is printing per the minute and also:

2015-01-05 08:31  PRINT <zipline._protocol.SidView object at 0x7fee66178fc8>  
2015-01-05 08:31 DEPRECATION WARNING Line 24: `data[sid(N)]` is deprecated. Use `data.current`.  Learn more here.  
2015-01-05 08:32  PRINT <zipline._protocol.SidView object at 0x7fee66178fc8>  
2015-01-05 08:33  PRINT <zipline._protocol.SidView object at 0x7fee66178fc8>  
2015-01-05 08:34  PRINT <zipline._protocol.SidView object at 0x7fee66178fc8>  
2015-01-05 08:35  PRINT <zipline._protocol.SidView object at 0x7fee66178fc8>  

My data is daily data, how do I change it to daily?

** Edit 2 **

Ok so I can now read and print the data after def handle_data(context, data):

from pytz import timezone  
import pandas

 # Preview the inported data frame  
def preview(df):  
    log.info(df.head())  
    return df

def time_lag(df):  
    # Correct look-ahead bias in mapping data to times  
    df = df.tshift(1, freq='b')  
    log.info(' \n %s ' % df.head())  
    return df

def initialize(context):  
    # Robinhood settings  
    set_long_only()  
    set_commission(commission.PerShare(cost=0, min_trade_cost=0))  
    context.allocation = 0.95 # Robinhood requires either limit orders or a 5% margin on orders.  
    # Fetch CSV from external source  
    fetch_csv('https://docs.google.com/spreadsheets/d/1EoT-AXs4wY88_kEsOkaYVX1KCpnovu4FwUZC1FTw9DQ/pub?gid=262287766&single=true&output=csv',  pre_func = preview, post_func=time_lag, usecols=['signal'], date_column = 'Date', symbol='signal')  
    # Set Symbol to buy  
    context.security = symbol('UPRO') 

    ####  
def handle_data(context, data):  
    current_signal = data.current('signal', 'signal')  
    print(current_signal)