Home > database >  How to print table in looping pyhton console
How to print table in looping pyhton console

Time:07-04

I want to print a table on my console. From now am using pandas how to print using tabulate

Here is my Source code:

from numpy import average
import pandas as pd

z = 10119011
a = 17
c = 43
m = 499

for i in range(0, 21):
    LCG = ((a*z) c) % m
    z = LCG
    u = z/m
    hasil = 700   u * (1500-700 1)

    d = {
        'Random Number Integer': [z],
        'Uniform Random Number': [u],
        'Penggunaan Pertamax/hari': [hasil]
    }
    df = pd.DataFrame(data=d)
    print(df)

CodePudding user response:

If you use tabulate, you need to pass your dataframe df as main argument and specify its keys:

from numpy import average
import pandas as pd
from tabulate import tabulate

z = 10119011
a = 17
c = 43
m = 499

for i in range(0, 21):
    LCG = ((a*z) c) % m
    z = LCG
    u = z/m
    hasil = 700   u * (1500-700 1)

    d = {
        'Random Number Integer': [z],
        'Uniform Random Number': [u],
        'Penggunaan Pertamax/hari': [hasil]
    }
    df = pd.DataFrame(data=d)
    print(tabulate(df, headers='keys'))

Output:

      Random Number Integer    Uniform Random Number    Penggunaan Pertamax/hari
--  -----------------------  -----------------------  --------------------------
 0                      465                 0.931864                     1446.42
      Random Number Integer    Uniform Random Number    Penggunaan Pertamax/hari
--  -----------------------  -----------------------  --------------------------
 0                      463                 0.927856                     1443.21
      Random Number Integer    Uniform Random Number    Penggunaan Pertamax/hari
--  -----------------------  -----------------------  --------------------------
 0                      429                 0.859719                     1388.64
      Random Number Integer    Uniform Random Number    Penggunaan Pertamax/hari
--  -----------------------  -----------------------  --------------------------
 0                      350                 0.701403                     1261.82
      Random Number Integer    Uniform Random Number    Penggunaan Pertamax/hari
--  -----------------------  -----------------------  --------------------------
 0                        5                  0.01002                     708.026
      Random Number Integer    Uniform Random Number    Penggunaan Pertamax/hari
--  -----------------------  -----------------------  --------------------------
 0                      128                 0.256513                     905.467
      Random Number Integer    Uniform Random Number    Penggunaan Pertamax/hari
--  -----------------------  -----------------------  --------------------------
.....
  • Related