Hi, I'm a Quantopian Noob - really liking it but having a little trouble importing data.
I use fetcher to import a csv I have saved in dropbox as a signal, but then can't work out how to access the data using the column names from the csv file.
When I log the signal, I can see the column names/values as dictionary key/values in the output, so I know the data has been read in, however when I try access I get an error.
The fetcher examples I look at all seem to relabel the signal columns to 'price' to access, but I was hoping there was I way I could use the original column labels.
Example code:
Imported CSV
date, Weight1, Weight2
7/2/2012, 0.3, 0.7
10/1/2012, 0.3, 0.7
Reading data, and logging
def initialize(context):
url = "https://dl.dropboxusercontent.com/s/bt8z1vk41ugghyd/balance_matrix_tmp.csv"
fetch_csv(url,
date_column = "date",
date_format = "%m/%d/%Y",
symbol = 'testsig')
def handle_data(context, data):
data[sid(26578)]) #Need a sid for algo to build
testimport = data['testsig']
log.info(type(testimport))
log.info(testimport)
A sample of the log shows that 'Weight1' and 'Weight2' have been imported and exist in a dict internal to the data['testsig'] sid object.
2012-07-02handle_data:29INFO<class 'zipline.protocol.SIDData'>
2012-07-02handle_data:30INFOSIDData({'datetime': Timestamp('2012-07-02 00:00:00+0000', tz='UTC'),
'Weight2': 0.7,
'Weight1': 0.3,
'dt': Timestamp('2012-07-02 00:00:00+0000', tz='UTC'),
'vwap': <function _transform at 0xa9e4500>,
'mavg': <function _transform at 0xa9e4848>,
'returns': <function _transform at 0xa9e48c0>,
'stddev': <function _transform at 0xa9e4758>,
'sid': 'testsig',
'source_id': 'PandasRequestsCSVf59832d08861fceb7ab9ef58b56100e2', 'type': 9})
But if I try to access these items, eg:
testimport = data['testsig']['Weight1']
I get an error
Runtime exception: KeyError: 'Weight1'
However, relabeling 'Weight1' to 'price' in a post processing function as in other examples let's me access via
testimport = data['testsig'].price
Be great if I could access the 'Weight1' series by it's original label directly though.
Any help would be greatly appreciated.