繁体   English   中英

TypeError: with_column() 从 3 到 4 个位置 arguments 但给出了 5 个(python)

[英]TypeError: with_column() takes from 3 to 4 positional arguments but 5 were given (python)

我一直对 jupyter 笔记本中位置 arguments 的限制有疑问。 我试图了解 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

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM