0

My code-

out = []
for _, row in df.iterrows():
    name = " ".join(row[0:4])

    entities = []
    i = 0
    for n in row.index[0:4]:
        entities.append([i, i + len(row[n]), n])
        i += len(row[n])+1
    out.append([name, {"entities": entities}])

My Dataframe-

             house                  road                        sub_area
0         726/30/3                 road 10                         abcd   
1              977                 road 16                         efgh 

I am getting the error

line 12, in <module>
    name = " ".join(row[0:4])
TypeError: sequence item 0: expected str instance, float found

How do I resolve this issue?

1 Answer 1

1

Without having knowing what df is, we can only guess. But usually the problem is that one is trying to str.join something else than strings. So try this instead:

name = " ".join(map(str, row[0:4]))
Sign up to request clarification or add additional context in comments.

5 Comments

It doesn't work. TypeError: object of type 'float' has no len()
I have attached a screenshot of my dataframe
@bellatrix You get that error at the same line as before?
line 17, in <module> entities.append([i, i + len(row[n]), n]) TypeError: object of type 'float' has no len()
@bellatrix Then row[n] is a float, which does not have a length. Maybe you want to convert the float to a string first?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.