string - 如何连接数字字符串
问题描述
... # 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
解决方案
应该:
MemberID = df2['Guest Number'].astype(str).iloc[row_numberd2]
with open("./pdfs/" + MemberID + "%s.pdf" % i, "wb") as outputStream:
output.write(outputStream)
推荐阅读
- python - 在 Azure 函数中将连接字符串设置为应用程序设置/环境变量
- powershell - Hyper-V 在其中一个适配器上更改静态 MAC 地址
- flutter-web - Flutter 在 Windows 10 上找不到名称或 ID 与“chrome”匹配的设备
- javascript - 如何拼接()子数组中的元素?
- macos - 在 macOS 应用程序包中对 Automator 工作流文件进行代码签名
- sql-server - Spring Data JPA 异常:数据库中已经有一个名为“disease_view”的对象
- tensorflow - 如何创建一个 Keras 层来进行 4D 卷积(Conv4D)?
- ios - Xcode 11.3.1 没有将二进制第三方框架嵌入到包 (IPA)
- ios - Firestore分页查询未返回所有结果
- asp.net - 如何在 TextMode="Date" 中首先插入“日”而不是月 - ASP.NET C#