Navigation

    Backtrader Community

    • Register
    • 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/

    cerebro.run ValueError: invalid literal for int() with base 10

    General Code/Help
    4
    5
    2252
    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.
    • A
      atori last edited by

      Hi. I'm Japanese boy.
      I will try hard to write in English.

      I am doing the Adding a Data Feed of quickstart using pandas.
      But When cerebro.run, an error of ValueError: invalid literal for int () is issued.

      Do you know what is wrong?

      0_1515231462244_image_1.png
      0_1515231473137_image_2.png
      0_1515231482827_image_3.png

      1 Reply Last reply Reply Quote -1
      • P
        Paska Houso last edited by

        Your datetime in the dataframe seems to be an index.

        From the docs (just checked)

        • https://www.backtrader.com/docu/pandas-datafeed/pandas-datafeed.html
         - The new parameters have the names of the regular fields in the DataSeries and follow these conventions
            - datetime (default: None)
               - None : datetime is the “index” in the Pandas Dataframe
        

        And you are providing a name for datetime. It might be that. Let it be None.

        1 Reply Last reply Reply Quote 1
        • A
          atori last edited by

          Thank you for your reply.

          I solved it by deleting this!
          datetime='datetime'

          N 1 Reply Last reply Reply Quote 0
          • B
            bennetcole last edited by

            The error message invalid literal for int() with base 10 would seem to indicate that you are passing a string that's not an integer to the int() function . In other words it's either empty, or has a character in it other than a digit.

            You can solve this error by using Python isdigit() method to check whether the value is number or not. The returns True if all the characters are digits, otherwise False .

            if val.isdigit():
            

            The other way to overcome this issue is to wrap your code inside a Python try...except block to handle this error.

            Python2.x and Python3.x

            Sometimes the difference between Python2.x and Python3.x that leads to this ValueError: invalid literal for int() with base 10 .

            With Python2.x , int(str(3/2)) gives you "1". With Python3.x , the same gives you ("1.5"): ValueError: invalid literal for int() with base 10: "1.5".

            1 Reply Last reply Reply Quote 0
            • N
              nsananguly @atori last edited by

              @atori Can you suggest what did you do to correct the error ?
              I am also facing the same error.

              Error that I get is :
              ValueError -> 14 cerebro.run()

              ValueError: invalid literal for int() with base 10: '28-0'

              Seeking guidance on what has gone wrong and how can this be course corrected .

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors