'Why does it shows string index out of range while the characters are long enough?
Need some help to identify the issue here. I am trying to clean up a dataset using Pandas DataFrame in Jupyter Notebook. My DataFrame data looks like this: Click here for the Dataframe
And I am trying to use for loop to filter and remove the rows which do not contain anything with 'B', 'R', 'T', or 'L' at index 11 of each string from the df2["Data"] column.
for unit in df2["Data"]:
if unit[11] != "B":
if unit[11] != "R":
if unit[11] != "T":
if unit[11] != "L":
df2.drop(df2.index[df2['Data'] == unit], inplace = True)
However it prompts this error saying that "string index out of range", while if you look at the string, for example "Calculator BW_2_1: Number\ttt" it is clearly more than 11 characters, but any idea why does it still prompt such an error?
IndexError Traceback (most recent call last)
<ipython-input-15-e1d0470b9bfb> in <module>
1 for unit in df2["Data"]:
----> 2 if unit[11] != "B":
3 if unit[11] != "R":
4 if unit[11] != "T":
5 if unit[11] != "L":
IndexError: string index out of range
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
