In working on a project, I came across this error I don’t understand.
Basically, I’m writing a function that’s meant to talk a list of lists (
list) and an empty list (
new_list) as arguments, and then look at the 5th column (index 4) for each row, assess whether the characters in the string are numeric, and then if they are, append the entire row to
I realize this isn’t the most efficient way of doing this anyway (still learning numpy, pandas, and vectorization), but I still don’t understand the error below, “string index out of range”.
Shouldn’t it be a list index? I know that
list has more than 5 columns, so I’m confused about:
- what it means by string index
- why it’s looking at that instead of
and also possibly whether this function would work correctly otherwise.
def clean_comments(list, new_list): for row in list: comment = row if comment.isnumeric == True: new_list.append(row)
<ipython-input-15-bcd2ead7d47c> in clean_comments(list) 3 def clean_comments(list): 4 for row in list: ----> 5 comment = row 6 if comment.isnumeric == True: 7 clean_ask_list.append(row) IndexError: string index out of range