I am running the below bit of code and getting the subject error; however there are no floats in the data set I'm testing with right now (there are blanks), so not sure why it's throwing that error? Even more so when there is an else statement to handle the case when item.isdigit() is not True?
for item in df['Vehicle Number']:
if item.isdigit():
if item[0] == "0":
df['Vehicle Number'] = df['Vehicle Number'].replace([item], item[1:4])
elif re.search(pattern, item):
match = re.search(pattern, item)
idx = match.span() # determine the start/finish of the pattern
start = idx[0]+2
end = idx[1]
if item[start] == "0":
df['Vehicle Number'] = df['Vehicle Number'].replace([item], item[start+1:end])
else:
df['Vehicle Number'] = df['Vehicle Number'].replace([item], item[start:end])
By converting the 'Vehicle Number' column to strings using
.astype(str), you ensure that all values are treated as strings, and then you can apply string methods like.isdigit()