0

I'm using this code:

for each in x: 
            descrVar = descrVar + " " + df.iloc[counter,each]

to iterate through a table and concatenate cells into a variable. The problem is, some of the cells will be a Nan. As a result, I'm getting the following error:

TypeError: can only concatenate str (not "numpy.float64") to str

I assume this means a Nan is a float64 and not a str. Is there any way around this, such as forcing every cell to convert to a str?

1 Answer 1

1

An f-string will format your data as str.

for each in x:
    descrVar += f" {df.iloc[counter,each]}"
Sign up to request clarification or add additional context in comments.

Comments

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.