我想将 timedelta 转换为 int,以便我可以用它做数学运算,但我一直收到此错误:
numpy.core._exceptions._UFuncBinaryResolutionError: ufunc 'true_divide' cannot use operands with types dtype('O') and dtype('<m8[D]')
代码如下:
zeit = datetime(2023, 1, 1)
today = datetime.now()
new_date = zeit-today
days_int=(new_date / np.timedelta64(1, 'D')).astype(int)
最佳答案
如果您只想转换 int 中的天数,请使用 new_date.days
关于python - 将 timedelta 转换为 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67102352/