簡體   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