2023-01-08

Python - How to create a dataframe with a matrix of random numbers

 import pandas as pd

import numpy as np

from tabulate import tabulate


# 100 rows, 3 columns, random numbers

df = pd.DataFrame(

        np.random.rand(100, 3),

        columns=['COLUMN_1', 'COLUMN_2', 'COLUMN_3']

    )


# Pretty-print it

print(tabulate(df, headers='keys', tablefmt='grid', showindex='always'))




No comments:

Post a Comment