For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Including data from a database



  • I try to use time series from a SQL Database which I created. The problem is that this pandas.core.frame.DataFrame can not be used for the trading strategy. There is the following output:


    AttributeError Traceback (most recent call last)
    <ipython-input-18-482559afee4d> in <module>()
    18
    19
    ---> 20 cerebro.adddata(data0)
    21
    22 results=cerebro.run()

    C:\ProgramData\Anaconda2\lib\site-packages\backtrader\cerebro.pyc in adddata(self, data, name)
    756
    757 data._id = next(self._dataid)
    --> 758 data.setenvironment(self)
    759
    760 self.datas.append(data)

    C:\ProgramData\Anaconda2\lib\site-packages\pandas\core\generic.pyc in getattr(self, name)
    2670 if name in self._info_axis:
    2671 return self[name]
    -> 2672 return object.getattribute(self, name)
    2673
    2674 def setattr(self, name, value):

    AttributeError: 'DataFrame' object has no attribute 'setenvironment'



  • It would be helpful to add some of your code for debugging. I don't load data from a database but from a csv file that I load in a panda DataFrame, so I suppose that there's a little issue along the way which we can't really find without any code.


  • administrators

    @predri said in Including data from a database:

    AttributeError: 'DataFrame' object has no attribute 'setenvironment'

    Yes. You cannot pass a DataFrame to cerebro and expect things to work.

    As pointed out by @Laurent-Michelizza, showing us what you do could be helpful.