Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Problem with fetcher_csv?

I'm trying to read a csv file (url=https://raw.github.com/scubamut/finlib/master/finlib/data.csv) with fetcher_csv - gives runtime error "Wrong number of items passed 1, indices imply 26".

pandas.io.parsers.read_csv(url) or even pandas.read_csv(url) work fine though, returning:-


Int64Index: 1398 entries, 0 to 1397
Data columns:
Date 1398 non-null values
....... .....

as expected.

Am I doing something wrong?

6 responses

Hi Dave, I think the problem is the Date column.

The attached backtest loads your csv and outputs the first three sids with prices:

2007-11-01 PRINT BND: 62.83, DBC: 28.93, DIA: 117.36,  

Thanks for the solution. pandas.read_csv doesn't seem to mind the dates though....

Hi Dennis,

I want to use this data in an algorithm (as sid data), but I'm struggling to understand how to do it. I can read in the data, thanks to your help, but can't figure out how to split the 'csv' SIDData item into separate SIDData items for each symbol, containing the OHLC etc. data for each.

Some help would be greatly appreciated!

Hi Dave - I took a look. The problem is the file format. The column name in the CSV itself must be "symbol" and the value of the column is the stocks's symbol.

Here's what you have:

Date,minor,BND,DBC,DIA,EEB,EFA,EPP,EWC,EWZ,FBT,FXI,FXY,IEF,IHE,ILF,INP,MDY,MYY,SHY,SPY,TLT,UUP,VDC,VNQ,VWO  
2007-11-01 00:00:00,open,62.574559999999998,29.093337761541019,119.09642694147959,49.721889947851103,72.099798315339896,47.89853573470554,32.55368061485909,69.013290454436159,25.646491228070179,63.388940143042277,86.579999999999998,71.697944850341742,50.819461055740121,45.508920802371684,89.769999999999996,153.92557885593743,56.343294400549638,75.465260115606938,136.15740912401509,73.365725619834706,23.639916072177929,61.503464510589581,55.27049892163911,49.284511710119311  

Here's what you need:

Date    minor   symbol  myprice  
11/1/2007 0:00  open    BND 62.57456  
11/1/2007 0:00  open    DBC 29.09333776  
11/1/2007 0:00  open    DIA 119.0964269  
11/1/2007 0:00  open    EEB 49.72188995  
11/1/2007 0:00  open    EFA 72.09979832  
11/1/2007 0:00  open    EPP 47.89853573  
11/1/2007 0:00  open    EWC 32.55368061  
11/1/2007 0:00  open    EWZ 69.01329045  
11/1/2007 0:00  open    FBT 25.64649123  
11/1/2007 0:00  open    FXI 63.38894014  
11/1/2007 0:00  open    FXY 86.58  
11/1/2007 0:00  open    IEF 71.69794485  
11/1/2007 0:00  open    IHE 50.81946106  
11/1/2007 0:00  open    ILF 45.5089208  
11/1/2007 0:00  open    INP 89.77  
11/1/2007 0:00  open    MDY 153.9255789  
11/1/2007 0:00  open    MYY 56.3432944  
11/1/2007 0:00  open    SHY 75.46526012  
11/1/2007 0:00  open    SPY 136.1574091  
11/1/2007 0:00  open    TLT 73.36572562  
11/1/2007 0:00  open    UUP 23.63991607  
11/1/2007 0:00  open    VDC 61.50346451  
11/1/2007 0:00  open    VNQ 55.27049892  
11/1/2007 0:00  open    VWO 49.28451171
Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

@Dan, I reshaped the dataframe to look like your example using pre_func . However the values still aren't showing up in the data[] object. Ideas?

Date       symbol minor  value  
2007-11-01 BND    open   62.574560  
2007-11-01 BND    high   62.838240  
2007-11-01 BND    low    62.574560  
2007-11-01 BND    close  62.830000  
2007-11-01 BND    volume 141200.000000  
2007-11-01 BND    price  62.830000  
2007-11-01 DBC    open   29.093338  
2007-11-01 DBC    high   29.093338  
2007-11-01 DBC    low    28.670581  
2007-11-01 DBC    close  28.930000  
2007-11-01 DBC    volume 378300.000000  
2007-11-01 DBC    price  28.930000  
2007-11-01 DIA    open   119.096427  
2007-11-01 DIA    high   119.130983  
2007-11-01 DIA    low    116.953970  
2007-11-01 DIA    close  117.360000  
2007-11-01 DIA    volume 25301400.000000  
2007-11-01 DIA    price  117.360000  

@Dennis, I uploaded a new frame.csv , according to Dan's spec, to github before I saw your post. Sorry if I have confused you (: I'm still trying to figure out how to get my test to work with the new frame...