Python TypeError:+;的操作数类型不受支持:';int';和';str';在一个以前执行得很好的程序中

Python TypeError:+;的操作数类型不受支持:';int';和';str';在一个以前执行得很好的程序中,python,string,int,operands,Python,String,Int,Operands,在这样做的时候 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' _-------

在这样做的时候

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回溯(最近一次调用上次) 在()

TypeError:不支持+:“int”和“str”的操作数类型


其中quandl.get将一个数据帧返回到max。我在另一个代码中也得到了相同的错误。我以前在同一代码的多次执行中没有遇到过这种情况。现在就开始。欢迎任何帮助。谢谢

您需要先将
年份
转换为字符串,然后再连接它

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

year
是一个整数。不能连接整数和字符串。我们不知道您以前的代码是什么样子,但您肯定没有使用此代码。
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