Feb-26-2021, 09:38 PM
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 0def 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
