【发布时间】:2020-02-07 00:10:11
【问题描述】:
我在 Jupyter Notebooks 中编写了以下代码用于练习:
method=['Take the Bus to Work', 'Drive to Work']
number_coworkers= [12, 15]
coffee=Table().with_columns('Method', method, 'Number of Coworkers', number_coworkers)
total_cups_day = coffee.column(0) * coffee.select("Average Cups of Coffee per Day")
number_cups_day_difference = total_cups_day.item(2) - total_cups_day.item(1)
number_cups_week_difference = number_cups_difference * 7
yearly_cups = number_cups_week_difference * 52
我收到以下错误:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-6-aad814252e94> in <module>
6 method=['Take the Bus to Work', 'Drive to Work']
7 number_coworkers= [12, 15]
----> 8 coffee=Table().with_columns('Method', method, 'Number of Coworkers', number_coworkers)
9 total_cups_day = coffee.column(0) * coffee.select("Average Cups of Coffee per Day")
10 number_cups_day_difference = total_cups_day.item(2) - total_cups_day.item(1)
NameError: name 'Table' is not defined
我在其他 Jupyter Notebooks 中看到了类似的方法,其中没有导入 Table,所以我不确定这个错误。
感谢您的帮助!
【问题讨论】:
-
您在与
astropy合作吗? Table() might be a reference to this -
您必须导入
Table。基于方法.with_columns(),看起来这是在datascience包中。你可以使用from datascience.tables import Table -
你缺少以
import ...开头的行 -
您从该错误消息中了解/不了解什么?