简体   繁体   中英

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

I have been having issue with the limits of positional arguments in jupyter notebook. Im trying to To get a sense of the variability in the number of heads in 100 tosses, we can collect the results in a table and draw a histogram.

         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() can add or replace only one column at a time, so rewrite it to:

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

or

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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