2

I have a list of numbers like this: (0, .5, .9, .99) and I need to run a function on each element of this list and save the result as a column in a table. I am using code below:

list = make_array(0, 0.5, 0.9, 0.99)
c = Table().with_column("Values", list)
for i in list:
    x = c.with_column("Limits", function(i))

What I get after running this code is a table with all values equal to the function applied to the last element of the array ( .99 ** 4 )

How can i modify it so i can get the correct table:

0    -> 0
0.5  -> 0.0625
0.9  -> 0.6561
0.99 -> 0.9605

Code:

schaefferda
  • 338
  • 1
  • 4
  • 14
merchmallow
  • 774
  • 3
  • 15

1 Answers1

0

I would create a dataframe with pandas then use ipython to display the dataframe.

import pandas as pd
from IPython.display import display, #HTML

xlist = [0, 0.5, 0.9, 0.99]
ylist = []
for x in xlist:
     #float might not be needed
     yl = float(x)**4
     ylist.append(yl)


xset = tuple(xlist)
yset = tuple(ylist)

df = pd.DataFrame({'values': xset, 'limits': yset})
display(df)

If you need more reference to display, this link should help. Show DataFrame as table in iPython Notebook

John T
  • 234
  • 1
  • 6