Wilder’s RSI in Python

Prototype of Wilder's RSI indicator.
Not functioning properly, needs to be fixed.

def compute_wildersRSI(data, time_window):
    diff = data.diff(1).dropna()        # diff in one field(one day)

    #this preservers dimensions 
    up_chg = 0 * diff
    down_chg = 0 * diff
    up_chg_avg   = 0 * up_chg
    down_chg_avg = 0 * down_chg    

    # up change is equal to the positive difference, otherwise equal to zero
    up_chg[diff > 0] = diff[ diff>0 ]

    # down change is equal to negative deifference, otherwise equal to zero
    down_chg[diff < 0] = diff[ diff < 0 ]

    # these are pandas series
    up_chg_avg.iloc[0]   = up_chg.iloc[0]
    down_chg_avg.iloc[0] = down_chg.iloc[0]    

    for i in range(1, len(up_chg_avg)):
        print('i: ', i)
        up_chg_avg.iloc[i]   = up_chg_avg.iloc[i-1] + (1/time_window * (data.iloc[i] - up_chg_avg.iloc[i-1]) )
        down_chg_avg.iloc[i] = down_chg_avg.iloc[i-1] + (1/time_window * (data.iloc[i] - down_chg_avg.iloc[i-1]) )

    print(up_chg_avg)

    rs = abs(up_chg_avg/down_chg_avg)
    rsi = 100 - 100/(1+rs)
    return rsi