Backtrader Community

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    ./panda-test.py --noheaders -> AttributeError: 'numpy.int64' object has no attribute 'lower

    General Code/Help
    2
    3
    360
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      Jerzy last edited by

      the example ./panda-test.py --noheaders in Data-Feed panda section of the documentatioin gives an error:

      feeds/pandafeed.py", line 212, in <listcomp>
          colnames = [x.lower() for x in self.p.dataname.columns.values]
      AttributeError: 'numpy.int64' object has no attribute 'lower'
      

      without --noheaders works just fine.
      What is a problem with --noheaders

      1 Reply Last reply Reply Quote 0
      • run-out
        run-out last edited by

        Can you show the code you are trying to run please?

        RunBacktest.com

        1 Reply Last reply Reply Quote 0
        • J
          Jerzy last edited by

          python ./panda-test.py --noheaders
          from __future__ import (absolute_import, division, print_function,
                                  unicode_literals)
          
          import argparse
          
          import backtrader as bt
          import backtrader.feeds as btfeeds
          
          import pandas
          
          
          def runstrat():
              args = parse_args()
          
              # Create a cerebro entity
              cerebro = bt.Cerebro(stdstats=False)
          
              # Add a strategy
              cerebro.addstrategy(bt.Strategy)
          
              # Get a pandas dataframe
              datapath = ('../../datas/2006-day-001.txt')
          # Simulate the header row isn't there if noheaders requested
              skiprows = 1 if args.noheaders else 0
              header = None if args.noheaders else 0
          
              dataframe = pandas.read_csv(datapath,
                                          skiprows=skiprows,
                                          header=header,
                                          parse_dates=True,
                                          index_col=0)
          
              if not args.noprint:
                  print('--------------------------------------------------')
                  print(dataframe)
                  print('--------------------------------------------------')
          
              # Pass it to the backtrader datafeed and add it to the cerebro
                                                                
             data = bt.feeds.PandasData(dataname=dataframe)
          
              cerebro.adddata(data)
          
              # Run over everything
              cerebro.run()
          
              # Plot the result
              cerebro.plot(style='bar')
          
          
          def parse_args():
              parser = argparse.ArgumentParser(
                  description='Pandas test script')
          
              parser.add_argument('--noheaders', action='store_true', default=False,
                                  required=False,
                                  help='Do not use header rows')
          
              parser.add_argument('--noprint', action='store_true', default=False,
                                  help='Print the dataframe')
          
              return parser.parse_args()
          
          
          if __name__ == '__main__':
              runstrat()
          
          
          1 Reply Last reply Reply Quote 1
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors