Convert the full for loop using pandas dataframe?

I want to change this for loop to Dataframe operation. this code find open high close low from volume and price column using own formula.this code works fine with for loop but it takes too much time i need to reduce the timings using the Dataframe operations but i don't find how to do this by dataframe

    import os
    import matplotlib.pyplot as plt
    import matplotlib.patches as mpatches
    import pandas as pd
    import numpy
    import sys
    from csv import writer
    from pathlib import Path
    from glob import glob
    from operator import itemgetter
    import concurrent.futures
    import time
    import datatable as dt

    def genBricksFromTrades(brick_size):
       column_names = ["datetime", "open", "high","low","close","volume"]
       bricks_df = pd.DataFrame()
       bricks = []
       dict = {}
       i=0
       up = 0
       dwn = 0
       t = 0
       c = 0
       v = 0
    
    
       trades_dataframe = dt.fread('input.csv.gz').to_pandas()
       new_df=trades_dataframe
       print(trades_dataframe.head())

    
    
       #trades_dataframe = pd.read_csv("input.csv.gz", compression="gzip", delimiter=",",   parse_dates=["timestamp"], header=0, squeeze=False,
                            #error_bad_lines=False)
       #print(trades_dataframe.head())
    
       trades_dataframe = trades_dataframe.set_index(trades_dataframe["timestamp"])
       del trades_dataframe["timestamp"]

       # Create volume series from volume column and will missing volume data with 0
       volume_series = trades_dataframe["volume"].fillna(0)
       new_df['volume'].fillna(0)
       # Create price series from price column and forward-fill missing price data
       price_series = trades_dataframe["price"].ffill()
       new_df["price"].ffill()
       print(new_df.head())
  
       for index, price, volume in zip(price_series.index, price_series, volume_series):
           
           if (t == 0 and c == 0):
               c = price
               up = price + (brick_size - (price % brick_size))
               dwn = price - (price % brick_size)
               print(index,price,volume)
               print(up,dwn)
            
           if (price > up and up != 0):
          
               bricks.append({
                   "datetime": index,
                   "open": price - (price % brick_size) - brick_size if t == -1 else c,
                   "high": price - (price % brick_size),
                   "low": price - (price % brick_size) - brick_size if t == -1 else c,
                   "close": price - (price % brick_size),
                   "volume": v
               })
            
            
               dict[i] = {
                   "datetime": index,
                   "open": price - (price % brick_size) - brick_size if t == -1 else c,
                   "high": price - (price % brick_size),
                   "low": price - (price % brick_size) - brick_size if t == -1 else c,
                   "close": price - (price % brick_size),
                   "volume": v
               }
               i=i+1
               #print('list',bricks)
               #print(b.head())
               print('up',up,price,volume)
               t = 1
               v = 0
               c = price - (price % brick_size) 
               up = c + brick_size
               dwn = c - 2 * brick_size
            


           if (price < dwn and dwn != 0):
            
            
               bricks.append({
                   "datetime": index,
                   "open": price + brick_size - (price % brick_size) + brick_size if t == 1 else c,
                   "high": price + brick_size - (price % brick_size) + brick_size if t == 1 else c,
                   "low": price + brick_size - (price % brick_size),
                   "close": price + brick_size - (price % brick_size),
                   "volume": v
               })
            
          
               dict[i] = {
                   "datetime": index,
                   "open": price + brick_size - (price % brick_size) + brick_size if t == 1 else c,
                   "high": price + brick_size - (price % brick_size) + brick_size if t == 1 else c,
                   "low": price + brick_size - (price % brick_size),
                   "close": price + brick_size - (price % brick_size),
                   "volume": v
               }
               i=i+1
               print('down',dwn,price,volume)
               t = -1
               v = 0
               c = price + brick_size - (price % brick_size) 
               up = c + 2 * brick_size
               dwn = c - brick_size

           v += volume

       df_1 = pd.DataFrame.from_dict(dict, "index")
       #print(df_1.head())
       # Save CSV in bricks directory
       #start_2=time.time()
       #df=pd.DataFrame(bricks)
       df_1.round({"open":2, "high":2, "low":2, "close":2,"volume":2}) 
       df_1.to_csv('out.csv',index = False)
       #print('append time_2 ',time.time()-start_2)
    
       start=time.time()
       for index, brick in enumerate(bricks):
        
           if (index != 0):
            
               append_list_as_row(bricks_file, [
                   brick["datetime"],
                   round(brick["open"], 2),
                   round(brick["high"], 2),
                   round(brick["low"], 2),
                   round(brick["close"], 2),
                   round(brick["volume"], 2),
                   0
               ])
       print('append time ',time.time()-start)
    

    
    import time    
    if __name__ == "__main__":
        start=time.time()
        genBricksFromTrades(25)
        print('Execution_time ',time.time()-start)

sample input this id the input i am using the csv file which is extracted from .gz

sample input csv file

sample output this is the output i expected

sample output from the above code