首页 > 解决方案 > 如何连接数字字符串

问题描述

       ... # etc               
       MemberID = df2['Guest Number'][row_numberd2]
       MemberI = int(MemberID) # tried converting it to int
       print (MemberI)

       with open("./pdfs/" + MemberI + "%s.pdf" % i, "wb") as outputStream:
             output.write(outputStream)  
           # etc, yes, have tried using MemberI and MemberID above, both wont concatenate        

以上输出以下错误;当它是一个字符串时。当我转换为 int 时,它说它需要是字符串才能连接。关于如何实现这一目标的任何想法?

TypeError: can only concatenate str (not "numpy.int64") to str # error using MemberID


TypeError: can only concatenate str (not "int") to str # Error using MemberI

标签: stringintegerintpython-3.7

解决方案


应该:

MemberID = df2['Guest Number'].astype(str).iloc[row_numberd2]
with open("./pdfs/" + MemberID + "%s.pdf" % i, "wb") as outputStream:
             output.write(outputStream) 

推荐阅读