def _create_tabulation(measurements: pd.DataFrame) -> pd.DataFrame:
    """Returns a sum of 0 and 1 results per index from a list of measurements."""
    if 'num_pulses' in measurements.columns:
        cols = [measurements.delay_ns, measurements.num_pulses]
    else:
        cols = [measurements.delay_ns]
    tabulation = pd.crosstab(cols, measurements.output).reset_index()
    # If all measurements are 1 or 0, fill in the missing column with all zeros.
    for col_index, name in [(1, 0), (2, 1)]:
        if name not in tabulation:
            tabulation.insert(col_index, name, [0] * tabulation.shape[0])
    return tabulation
Returns a sum of 0 and 1 results per index from a list of measurements.
cirq-core/cirq/experiments/t2_decay_experiment.py