-6

Here is the error I can't seem to squash, dropping down my count to be one less than my actual rows fixes it, but that means it can't even read the last row. The error is coming from me attempting to parse data from my .csv I have saved in the same directory.

Here is the code that seems to be causing the issue:

    margin1 = datetime.timedelta(days = 1)
    margin3 = datetime.timedelta(days = 3)
    margin7 = datetime.timedelta(days = 7)
    df = pd.read_csv('gameDB.csv')
    a = df.values
    rows=len(df.index)
    while (x <= rows):
        print (rows)
        print (x)
        input("Press Enter to continue...")
        csvName = str((df.iloc[x,0]))
        csvRel = str((df.iloc[x,1]))
        csvCal = str((df.iloc[x,2]))
        from datetime import datetime
        today = datetime.strptime(twiday, '%Y-%m-%d').date()
        compDate = datetime.strptime(csvRel, '%Y-%m-%d').date()
        print (csvName + ' ' + csvRel + ' ' + csvCal)
        try:
            if (today+margin7 == compDate):
                #tweet = (csvName + ' releases in 7 days. Click here to add to calendar ' + csvCal)
                #api.update_status(tweet)
                time.sleep(10)
            elif (today+margin3 == compDate):
                #tweet = (csvName + ' releases in 3 days. Click here to add to calendar ' + csvCal)
                #api.update_status(tweet)
                time.sleep(10)
            elif (today+margin1 == compDate):
                #tweet = (csvName + ' releases in tomorrow. Click here to add to calendar ' + csvCal)
                #api.update_status(tweet)
                time.sleep(10)
            elif (today == compDate):
                #tweet = (csvName + ' is now released.')
                #api.update_status(tweet)
                time.sleep(10)
        except:
            continue
        x += 1

And Here is the error i get

Traceback (most recent call last):
  File ".\gameRelease.py", line 306, in <module>
    NintendoSwitch()
  File ".\gameRelease.py", line 277, in NintendoSwitch
    main(system,data,color,calID)
  File ".\gameRelease.py", line 270, in main
    twitUpdate(tDay)
  File ".\gameRelease.py", line 97, in twitUpdate
    csvName = str((df.iloc[x,0]))
  File "C:\Users\UmbraTytan\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\indexing.py", line 1367, in __getitem__
    return self._getitem_tuple(key)
  File "C:\Users\UmbraTytan\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\indexing.py", line 1737, in _getitem_tuple
    self._has_valid_tuple(tup)
  File "C:\Users\UmbraTytan\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\indexing.py", line 204, in _has_valid_tuple
    if not self._has_valid_type(k, i):
  File "C:\Users\UmbraTytan\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\indexing.py", line 1672, in _has_valid_type
    return self._is_valid_integer(key, axis)
  File "C:\Users\UmbraTytan\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pandas\core\indexing.py", line 1713, in _is_valid_integer
    raise IndexError("single positional indexer is out-of-bounds")
IndexError: single positional indexer is out-of-bounds
cowbert
  • 3,212
  • 2
  • 25
  • 34
  • 3
    How to create a Minimal, Complete, and Verifiable example: https://stackoverflow.com/help/mcve – jpp Jan 26 '18 at 00:55
  • Could you show the code ? – KeLiuyue Jan 26 '18 at 01:04
  • Sure, I can upload all of it, one sec – UmbraChimera Jan 26 '18 at 01:05
  • Added more information – UmbraChimera Jan 26 '18 at 01:11
  • Think carefully about the logic. If there are 5 rows, then what are the valid indices? (If your answer was something other than "0, 1, 2, 3 and 4", then please study more carefully.) Now, what will `while (x <= rows):` do? If `rows` is equal to `5` (because there are 5 rows), and `x` is equal to `5` (because of the loop), will the code run again? (Hint: what does `<=` mean?) Now, if `x` is equal to `5`, and you try to use that as an index, and `5` isn't a valid index, what do you expect to happen? – Karl Knechtel Aug 11 '22 at 05:53

2 Answers2

0

Forgot to add the header row when creating the csv on application start, that resolved all of it.

    writer.writeheader()

That's all it needed.

0

this is simply saying that one of your iloc statements is looking up something that doesn't exist. If your DataFrame is 5 rows long, iloc[5, 0] would give out-of-bounds. This is because the last row would be iloc[4, 0], as it begins counting from 0.