res = new.groupby(['id', 'survey_sequence', 'option_order'])['question_value'].agg('|'.join)
TypeError: sequence item 0: expected str instance, int found“id”是对象,其余列是整数。为什么我会出现这个错误?感谢您的支持。
1 回答
![?](http://img1.sycdn.imooc.com/545847f50001126402200220-100-100.jpg)
慕雪6442864
TA贡献1812条经验 获得超5个赞
该函数'str'.join()
接受字符串,但您直接传递整数 ID。相反,您必须将整数转换为字符串,然后调用 .join。这可以通过利用 astype 函数在传递索引之前将索引转换为字符串来实现.join
:
res = new.groupby(['id', 'survey_sequence', 'option_order'])['question_value'].astype(str).agg('|'.join)```
添加回答
举报
0/150
提交
取消