TypeError Traceback (most recent call last) <ipython-input-94-942b147f7ea7> in <module> 7 8 # 计算参会时间 ----> 9 duration_col = (end_time_col - start_time_col).astype('timedelta64[m]') 10 11 # 将计算结果添加到表格中 D:\anaconda3\lib\site-packages\pandas\core\ops\common.py in new_method(self, other) 63 other = item_from_zerodim(other) 64 ---> 65 return method(self, other) 66 67 return new_method D:\anaconda3\lib\site-packages\pandas\core\ops\__init__.py in wrapper(left, right) 341 lvalues = extract_array(left, extract_numpy=True) 342 rvalues = extract_array(right, extract_numpy=True) --> 343 result = arithmetic_op(lvalues, rvalues, op) 344 345 return left._construct_result(result, name=res_name) D:\anaconda3\lib\site-packages\pandas\core\ops\array_ops.py in arithmetic_op(left, right, op) 184 if should_extension_dispatch(lvalues, rvalues) or isinstance(rvalues, Timedelta): 185 # Timedelta is included because numexpr will fail on it, see GH#31457 --> 186 res_values = op(lvalues, rvalues) 187 188 else: D:\anaconda3\lib\site-packages\pandas\core\arrays\datetimelike.py in __rsub__(self, other) 1520 # GH#19959 datetime - datetime is well-defined as timedelta, 1521 # but any other type - datetime is not well-defined. -> 1522 raise TypeError( 1523 f"cannot subtract {type(self).__name__} from {type(other).__name__}" 1524 ) TypeError: cannot subtract DatetimeArray from ndarray这行代码那里错误
时间: 2024-02-14 08:08:24 浏览: 47
这个错误是因为在计算 `duration_col` 时,`end_time_col` 和 `start_time_col` 的数据类型不一致,可能一个是 `DatetimeArray` 类型,一个是 `ndarray` 类型。需要将两者的数据类型一致化,可以通过将 `start_time_col` 转换成 `DatetimeArray` 类型来解决这个问题,例如:`start_time_col = pd.to_datetime(start_time_col)`。
相关问题
TypeError Traceback (most recent call last) <ipython-input-21-656cfe61f5bf> in <module>() 5 epochs=2, 6 validation_split=0.2, ----> 7 shuffle=True) 8 9 TypeError: fit() got an unexpected keyword argument 'batch_size'
这是一个关于 Python 代码中 fit() 函数的 TypeError,可能是由于 fit() 函数没有 batch_size 参数导致的。建议检查一下代码中的 fit() 函数,确认是否有输入正确的参数。如果需要更多的帮助,可以提供更详细的代码和错误信息,我会尽力帮忙解决问题。
TypeError Traceback (most recent call last) <ipython-input-2-b8ec604d943f> in <module>() 1 list1 = [1, 2, 3, 1, 2, 3, 4, 5, 1] ----> 2 list2 = list(set(list1)) 3 print(list2) TypeError: 'list' object is not callable
这个错误的原因是你把一个内置函数 `list()` 的名称赋值给了变量 `list2` ,导致程序无法调用内置函数 `list()` 。你可以尝试使用一个不同的变量名来解决这个问题。以下是一种正确的写法:
```
lst1 = [1, 2, 3, 1, 2, 3, 4, 5, 1]
lst2 = list(set(lst1))
print(lst2)
```
这里我们将变量名 `list1` 改为了 `lst1` ,将变量名 `list2` 改为了 `lst2`。