def build(self, show_digits=2, add_totals=True):
        """Build the binning table.

        Parameters
        ----------
        show_digits : int, optional (default=2)
            The number of significant digits of the bin column.

        add_totals : bool (default=True)
            Whether to add a last row with totals.

        Returns
        -------
        binning_table : pandas.DataFrame
        """
        _check_build_parameters(show_digits, add_totals)

        n_nonevent = self.n_nonevent.astype(int)
        n_event = self.n_event.astype(int)

        self._t_n_nonevent = n_nonevent.sum()
        self._t_n_event = n_event.sum()
        n_records = n_event + n_nonevent
        t_n_records = self._t_n_nonevent + self._t_n_event
        p_records = n_records / t_n_records

        mask = (n_event > 0) & (n_nonevent > 0)
        event_rate = np.zeros(len(n_records))
        event_rate[mask] = n_event[mask] / n_records[mask]

        self._n_records = n_records

        # Gini / IV / JS / hellinger / triangular / KS
        self._gini = self.d_metrics["Gini index"]
        self._iv = self.d_metrics["IV (Jeffrey)"]
        self._js = self.d_metrics["JS (Jensen-Shannon)"]
        self._hellinger = self.d_metrics["Hellinger"]
        self._triangular = self.d_metrics["Triangular"]
        self._ks = self.d_metrics["KS"]

        # Compute HHI
        self._hhi = hhi(p_records)
        self._hhi_norm = hhi(p_records, normalized=True)

        bins = np.concatenate([[-np.inf], self.splits, [np.inf]])
        bin_str = bin_str_format(bins, show_digits)

        if isinstance(self.special_codes, dict):
            self._n_specials = len(self.special_codes)
            bin_str.extend(list(self.special_codes) + ["Missing"])
        else:
            self._n_specials = 1
            bin_str.extend(["Special", "Missing"])

        df = pd.DataFrame({
            "Bin": bin_str,
            "Count": n_records,
            "Count (%)": p_records,
            "Non-event": n_nonevent,
            "Event": n_event
            })

        n_coefs = self.coef.shape[1]

        n_bins_extra = self._n_specials + 1
        for i in range(n_coefs):
            if i == 0:
                extra_bins = list(event_rate[-n_bins_extra:])
            else:
                extra_bins = [0] * n_bins_extra

            df["c{}".format(i)] = list(self.coef[:, i]) + extra_bins

        if add_totals:
            totals = ["", t_n_records, 1, self._t_n_nonevent, self._t_n_event]
            totals += ["-"] * n_coefs
            df.loc["Totals"] = totals

        self._is_built = True

        return df
Build the binning table.

        Parameters
        ----------
        show_digits : int, optional (default=2)
            The number of significant digits of the bin column.

        add_totals : bool (default=True)
            Whether to add a last row with totals.

        Returns
        -------
        binning_table : pandas.DataFrame
        
optbinning/binning/piecewise/binning_statistics.py