Python Forum
IndexError: index 0 is out of bounds for axis 0 with size 0
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IndexError: index 0 is out of bounds for axis 0 with size 0
#1
Hi friends, need your help. I have this problem with an Excel file wherein it works with my first file but second Excel has an error. Thanks!

Error:
Traceback (most recent call last): File "C:\DATA\python\app.py", line 442, in <module> main() File "C:\DATA\python\app.py", line 366, in main shortestSen = shortestSentence(baseDF) File "C:\DATA\python\app.py", line 258, in shortestSentence index = index[[0]] IndexError: index 0 is out of bounds for axis 0 with size 0
def shortestSentence(baseDF):
    addList = ["SENTENCE", "Sentence", "sentence"]
    shortValsList = []
    indexList = []
    d = {}
    for c in baseDF:
        for i in addList:
            if i[:4] in c:
                length = baseDF[c].astype(str).map(len)
                shortVal = baseDF.loc[length.idxmin(), str(c)]
                shortValsList.append(shortVal)
                index = np.flatnonzero(baseDF[c] == shortVal)
                index = index[[0]]
                indexList.append(index)
                d[shortVal] = index
            else:
                pass
    shortest = max(shortValsList, key = len)
    shortestInd = d[shortest]
    shortestSen = baseDF.iloc[shortestInd]
    return shortestSen
Reply
#2
Maybe there's no data in that cell? If you can post a minimally reproducible example, you might get more answers..
Reply
#3
(Feb-27-2021, 12:53 AM)nealc Wrote: Maybe there's no data in that cell? If you can post a minimally reproducible example, you might get more answers..

my Excel data is just any normal text with headers such as NAME1, NAME2, SENT1, SENT2...

and the contents are just words less than 50 characters.

I'm using pandas and numpy.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] Getting Index Error - list index out of range krishna 2 320 Jan-09-2021, 08:29 AM
Last Post: buran
  IndexError: index 0 is out of bounds for axis 0 with size 0 tmhsa 0 1,818 Apr-24-2020, 10:00 AM
Last Post: tmhsa
  Getting Index Error - list index out of range RahulSingh 2 2,109 Feb-03-2020, 07:17 AM
Last Post: RahulSingh
  pandas.read_sas with chunksize: IndexError list index out of range axelle 0 784 Jan-28-2020, 09:30 AM
Last Post: axelle
  IndexError: index out of bounds LeoGER 3 5,409 Sep-05-2019, 02:05 PM
Last Post: LeoGER
  How matplotlib automatically set x-axis and y-axis limits for bar graph ? ift38375 3 2,528 Jul-04-2019, 08:23 AM
Last Post: scidam
  Can you help me with this error? IndexError: invalid index of a 0-dim tensor. DerBerliner 1 2,128 Feb-28-2019, 05:47 PM
Last Post: Larz60+
  Regarding index out of bounds error and implementing Loop error in backpropagation al geevaprasa 6 5,398 Apr-20-2018, 09:35 AM
Last Post: Larz60+
  Unable to understand reason for error IndexError: tuple index out of range rajat2504 4 49,517 Dec-09-2016, 11:04 AM
Last Post: Kebap

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020