0

I need to get output in my jupyter notebook code in a table. Here is my code.

import numpy as np

for x in range(1,1000):
    y=2*x+3
    print(x,y)

I get the output like below.

enter image description here

I need it in a table with column names "x" and "y". When I scroll down, the column names should be visible.

Thank You.

1 Answers1

1

I think that, the cleanest way is to use pandas dataframe as follow:

import numpy as np
import pandas as pd

table=[]
for x in range(1,1000):
    y=2*x+3
    table.append([x,y])

df= pd.DataFrame(np.array(table_x),columns = ['x','y'])

print(df.head())

will give you

   x   y
0  1   5
1  2   7
2  3   9
3  4  11
4  5  13
Panda50
  • 901
  • 2
  • 8
  • 27