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-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: IndexError: index 0 is out of bounds for axis 0 with size 0 (/thread-32696.html) |
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!
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. |