python - 类型错误:+ 的不支持的操作数类型:“int”和“str”在之前执行良好的程序中
问题描述
在这样做的同时
year = 2019
tariq1 = year+'-01-01'
tariq2 = year+'-12-31'
while year > 2015:
for stock in string:
max=quandl.get(stock, start_date=tariq1, end_date=tariq2)
max
year = year - 1
在行中出现错误
tariq =year+'-01-01'
_---------------------------------------------------- ------------------------- TypeError Traceback (最近一次调用最后一次) in ()
1 year = 2019
----> 2 tariq1 = year+'-01-01'
3 tariq2 = year+'-12-31'
4 while year > 2015:
5 for stock in string:_
类型错误:+ 不支持的操作数类型:“int”和“str”
其中 quandl.get 将数据帧返回到最大值。我在另一个代码中也遇到了同样的错误。我之前在多次执行相同的代码时没有遇到过这种情况。现在才得到这个。欢迎任何帮助。谢谢
解决方案
您需要year
在连接之前转换为字符串。
year = 2019
tariq1 = str(year)+'-01-01'
tariq2 = str(year)+'-12-31'
while year > 2015:
for stock in string:
max=quandl.get(stock, start_date=tariq1, end_date=tariq2)
max
year = year - 1
附带说明一下,您可能还想更新循环内部的值,tariq1
而tariq2
不是在循环之前:
year = 2019
while year > 2015:
tariq1 = str(year)+'-01-01'
tariq2 = str(year)+'-12-31'
for stock in string:
max=quandl.get(stock, start_date=tariq1, end_date=tariq2)
max
year = year - 1
推荐阅读
- java - 基于 Java 的应用程序中 Arch Linux 中的字体问题
- python - Keras:绘制模型时出现断言错误
- git - git update mirror 不影响新分支
- php - 如何在 PHP SQLite3 bindparam 中使用变量作为参数名
- powershell - 如何使用 powershell 找出服务正常运行时间的持续时间?
- java - 如何使用 Spring 中另一个列表的属性创建列表?
- string - 使用 shell 脚本通过用户输入替换字符串中的文本
- c# - 在 C# 中显示@@ROWCOUNT
- r - 查找数字是否在范围列表中的最快方法是什么?
- r - 为什么这些段没有正确绘制?