Python类型错误问题TypeError:-:'Table'和'float'不受支持的操作数类型

凯撒大帝

我有一张桌子,上面放着一些IMDB电影(电影名称,等级,年份)。我想计算20世纪和21世纪所有电影的平均评分。

table_20th = imdb.where("Year",are.below(2000))
table_21th = imdb.where("Year",are.above_or_equal_to(2000))


rating_20th = table_20th.select("Rating")
rating_21th = table_21th.select("Rating")


average_20th_century_rating = float(np.average(rating_20th.column(0)))
average_21th_century_rating = float(np.average(rating_21th.column(0)))


print("Type 20th", type(average_20th_century_rating))
print("Type 21st", type(average_21th_century_rating))

print("Average 20th century rating:", average_20th_century_rating)
print("Average 21st century rating:", average_21st_century_rating)

print(abs(average_20th_century_rating - 8.2783625730994146) < 1e-5)
print(abs(average_21st_century_rating - 8.2379746835443033) < 1e-5)

20世纪电影的abs()起作用,但21世纪电影的abs引发类型错误。但是所有abs()参数都是浮点数。

产生以下输出

Type 20th <class 'float'>
Type 21st <class 'float'>
Average 20th century rating: 8.278362573099415
Average 21st century rating: Rating
8.23797
True

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-136-bc0060cc4666> in <module>()
     20 
     21 print(abs(average_20th_century_rating - 8.2783625730994146) < 1e-5)
---> 22 print(abs(average_21st_century_rating - 8.2379746835443033) < 1e-5)

TypeError: unsupported operand type(s) for -: 'Table' and 'float'

有人可以给我一个提示吗?

Снаđошƒаӽ

检查的最后两个用法average_21th_century_rating他们被错误地写成average_21st_century_rating绝对不是浮点数,而是一个type类Rating

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

TypeError:-:“ instance”和“ float”的不受支持的操作数类型

TypeError:-:“ float”和“ method”的不受支持的操作数类型

*:'float'和'Decimal'不受支持的操作数类型

Python:pct_change引发TypeError:/:'str'和'float'不受支持的操作数类型

TypeError:-:'str'和'float'python pandas的不受支持的操作数类型

Python错误:-:'float'和'NoneType'不受支持的操作数类型

matplotlib TypeError:-:“ datetime.date”和“ float”的不受支持的操作数类型

Python 3:/:“ float”和“ bytes”不受支持的操作数类型

TyperError:-:“ float”和“ builtin_function_or_method”的不受支持的操作数类型

“ /:'float'和'list'的不受支持的操作数类型”是什么意思?

TypeError:无法将“ float”对象隐式转换为str或TypeError:-:“ str”和“ float”的不受支持的操作数类型

TypeError:-:“模块”和“ LinearSegmentedColormap”的不受支持的操作数类型

TypeError:-:“近似”和“浮动”的不受支持的操作数类型

TypeError:-:“列表”和“列表”的不受支持的操作数类型

TypeError:|:“列表”和“列表”的不受支持的操作数类型

TypeError:-:“ tuple”和“ tuple”的不受支持的操作数类型

TypeError:-:“位置”和“位置”的不受支持的操作数类型

* 不支持的操作数类型:'map' 和 'float'

*:'instance'和'float'不支持的操作数类型

不支持 / 的操作数类型:'str' 和 'float'

“ **或pow()不受支持的操作数类型:“函数”和“整数””

-:'str'和'int'的不受支持的操作数类型

*-:'NoneType'和'NoneType'不受支持的操作数类型

Tensorflow:-:'Sequential'和'Sequential'的不受支持的操作数类型

Python 3:类型错误:+ 不支持的操作数类型:'float' 和 'str'

面对这个错误:-TypeError:不支持的操作数类型为-:'str'和'float'?

Python TypeError:^:'float'和'int'不支持的操作数类型

TypeError:+ =:Python 3中不支持的操作数类型为“ float”和“ NoneType”

TypeError:&:不支持的操作数类型:“ float”和“ float”,但我没有&