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

convert datas[0] into a pandas DataFrame

  • Re: Using backtrader data to make a Pandas dataframe from

    I have a similar issue, I'm creating a new indicator and I find it would be really useful to have the datas[0] (or to be able to convert it) as a pandas dataframe.

    There is a quantity of packages available in python to do advanced math using dataframes, additionally handling dataframes is so much easier and common practice that it just makes sense to have a as_dataframe method to get a pandas representation of it.

  • administrators

    One of goals of backtrader was to not rely on libraries which are not part of the standard Python distribution, no matter how many million users it may have.

    Adding a as_dataframe method would break that goal. Furthermore, understanding your point, you have to consider that the internal representation of the lines is not a table-like structure (like it is the case for a dataframe).

    You can slice, so to say, with the get method of a line and pass the resulting array to the dataframe constructor.

    See: Docs - Platform Concepts - Section: Slicing

Log in to reply