Python Forum
IndexError: index 0 is out of bounds for axis 0 with size 0 - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/Forum-Python-Coding)
+--- Forum: Data Science (https://python-forum.io/Forum-Data-Science)
+--- Thread: IndexError: index 0 is out of bounds for axis 0 with size 0 (/Thread-IndexError-index-0-is-out-of-bounds-for-axis-0-with-size-0--32696)



IndexError: index 0 is out of bounds for axis 0 with size 0 - atomxkai - Feb-26-2021

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



RE: IndexError: index 0 is out of bounds for axis 0 with size 0 - nealc - Feb-27-2021

Maybe there's no data in that cell? If you can post a minimally reproducible example, you might get more answers..


RE: IndexError: index 0 is out of bounds for axis 0 with size 0 - atomxkai - Mar-03-2021

(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.