Tunahan A.
Tunahan A.

Reputation: 142

How can I deal with sequence item 0 error?

res = new.groupby(['id', 'survey_sequence', 'option_order'])['question_value'].agg('|'.join)
TypeError: sequence item 0: expected str instance, int found

"id" is object and the rest of the columns are integers. Why am I having this error?

Thank you for your support.

Upvotes: 0

Views: 335

Answers (1)

Daniel O'Brien
Daniel O'Brien

Reputation: 365

The function 'str'.join() takes strings, however you're passing an integer ID directly. Instead, you have to convert the integer to a string, and then call .join. This can be achieved by utilising the astype function to convert the indexes to a string before passing them through .join:

res = new.groupby(['id', 'survey_sequence', 'option_order'])['question_value'].astype(str).agg('|'.join)```

Upvotes: 1

Related Questions