【问题标题】:TypeError: with_column() takes from 3 to 4 positional arguments but 5 were given (python)TypeError: with_column() 需要 3 到 4 个位置参数,但给出了 5 个(python)
【发布时间】:2021-02-06 13:47:03
【问题描述】:

我一直对 jupyter notebook 中位置参数的限制有疑问。 我试图了解 100 次投掷中正面数量的变化,我们可以将结果收集在表格中并绘制直方图。

         simulation_results = Table().with_column(
        'Repetition', np.arange(1, num_repetitions + 1),
        'Number of Heads', heads
    )
    
    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    <ipython-input-15-484d76c43683> in <module>
    ----> 1 simulation_results = Table().with_column(
          2     'Repetition', np.arange(1, num_repetitions + 1),
          3     'Number of Heads', heads
          4 )
    
    TypeError: with_column() takes from 3 to 4 positional arguments but 5 were given

【问题讨论】:

  • 我不确定你的问题到底是什么。您的调用有错误数量的参数,这就是错误所说的。如果这是您混淆的根源,那么调用中还有另一个隐藏参数self。请作为这里的新用户,使用tour 并阅读How to Ask。另外,尝试将有问题的代码简化为 minimal reproducible example 之类的内容,因为这里的人不知道你的上下文(而且猜测是不好的),而且它也让你更容易理解。
  • 什么是Table
  • @Tomerikoo: 表格来自datascience
  • @bvamos 你怎么知道?我在问题中没有看到任何线索......
  • @bvamos 我的意思是,您可能会认出,但其他人可能不会。我的评论更多的是针对 OP 而不是您。此类信息应edited 到问题中...

标签: python jupyter


【解决方案1】:

with_column()一次只能添加或替换一列,所以重写为:

simulation_results = Table().with_column(
  'Repetition', np.arange(1, num_repetitions + 1)
)
simulation_results = simulation_results.with_column(
  'Number of Heads', heads
)

simulation_results = Table()
.with_column('Repetition', np.arange(1, num_repetitions + 1))
.with_column('Number of Heads', heads)

【讨论】:

    猜你喜欢
    • 2022-01-17
    • 2022-06-19
    • 1970-01-01
    • 2021-04-14
    • 2021-10-05
    • 2018-03-07
    • 1970-01-01
    • 1970-01-01
    • 2020-10-28
    相关资源
    最近更新 更多