I always keep getting this error. I tried typecasting it with int but that does not works
CodePudding user response:
Patient age is an integer and cannot be sliced. The lambda function tries to slice the age but since an integer is not subscriptable like lists or tuples or strings, etc, you can't slice it.
CodePudding user response:
The column df['Patient Age']
dtype seems to be integer. Applying Lambda x: x[-1:]
doesn't work because integers aren't subscriptable; don't have an index.
# apply here will apply lambda on each value which is an integer
# intergers don't have index!
df['Patient Age'].apply(lambda x: x[-1:])