def log_geometric_mean(series: Series) -> float: """Returns the Logarithmic Geometric Mean""" n = series.size if n < 2: return 0 else: series = series.fillna(0) + 1 if npAll(series > 0): return npExp(npLog(series).sum() / n) - 1 return 0
def geometric_mean(series: Series) -> float: """Returns the Geometric Mean for a Series of positive values.""" n = series.size if n < 1: return series.iloc[0] has_zeros = 0 in series.values if has_zeros: series = series.fillna(0) + 1 if npAll(series > 0): mean = series.prod()**(1 / n) return mean if not has_zeros else mean - 1 return 0