TypeError: unsupported operand type(s) for +: 'getset_descriptor' and 'int'

Traceback (most recent call last):
  File "C:\Users\Administrator\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3326, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-2-4b80bb28613a>", line 1, in <module>
    runfile('D:/Python/Learning/pandasLearn.py', wdir='D:/Python/Learning')
  File "C:\Program Files\JetBrains\PyCharm 2019.3.2\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
    pydev_imports.execfile(filename, global_vars, local_vars)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm 2019.3.2\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "D:/Python/Learning/pandasLearn.py", line 42, in <module>
    test['D'].at[i] = add_month(start, i)
  File "D:/Python/Learning/pandasLearn.py", line 32, in add_month
    return date(date.year + year, month, date.day)
TypeError: unsupported operand type(s) for +: 'getset_descriptor' and 'int'

我这个错误其实错的也很明显了,TypeError说不支持操作类型'getset_descriptor' and 'int'相加,在这里插入图片描述
我这个date.year是getset_descriptor类型,第二个year是int类型,所以两个不能相加,我把变量名字看错了,只需改成正确的int类型就可以正常运行了:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/u011679785/article/details/104530687