python – the code is taking too long to be executed

My friend and I are working on a project. I wrote the code but the code is taking too long to be executed, I added the code down. I want help from those who know. In the following parts of the code, we changed the data type from float to int16 to reduce mem_usage, but Pipeline is running for too long and we can’t find the reason.

from pandas.util import hash_pandas_object
import pandas as pd
import hashlib
import typing
import random
import numpy as np
from multiprocessing import Pool, cpu_count
import psutil
import os


ROWS = 20000000


DATA: typing.List(float) = (random.random() for _ in range(ROWS))

def update_df(df_orig: pd.DataFrame, df_new: pd.DataFrame) -> pd.DataFrame:
    return pd.concat((df_orig, df_new), axis=1)

class Transform:
    """A transform that adds a column of random data"""

    def __init__(self, var: str):
        self.var = var

    def transform(self, df_orig: pd.DataFrame) -> pd.DataFrame:
        return update_df(df_orig, pd.DataFrame({self.var: DATA}))

class Pipeline:
    def __init__(self):
        self.df = pd.DataFrame()
        self.transforms = (Transform(f"v{i}") for i in range(TRANSFORMS))

    def run(self):
        for t in self.transforms:
            self.df = t.transform(self.df)
        return self.df

if __name__ == "__main__":
    pipe = Pipeline()
    df =
    print("Pipeline was run")
    df_hash = hashlib.sha256(
        pd.util.hash_pandas_object(df, index=True).values

    print("df_hash", df_hash)

    test_hash = "867567dc7d46f77af2bca9804ac366a5165d27612de100461b699bd23094ab90"
    assert df_hash == test_hash

    print("df hash was okay!")