Repository: pandas-dev/pandas
File: pandas/core/groupby/generic.py (Python)

Code before:
        ...         "A": ["foo", "bar", "foo", "bar", "foo", "bar"],
        ...         "B": ["one", "one", "two", "three", "two", "two"],
        ...         "C": [1, 5, 5, 2, 5, 5],
        ...         "D": [2.0, 5.0, 8.0, 1.0, 2.0, 9.0],
        ...     }
        ... )
        >>> grouped = df.groupby("A")[["C", "D"]]
        >>> grouped.transform(lambda x: (x - x.mean()) / x.std())
            C         D
        0 -1.154701 -0.577350
        1  0.577350  0.000000
        2  0.577350  1.154701
        3 -1.154701 -1.000000
        4  0.577350 -0.577350
        5  0.577350  1.000000

        Broadcast result of the transformation

        >>> grouped.transform(lambda x: x.max() - x.min())
            C    D
        0  4.0  6.0
        1  3.0  8.0
        2  4.0  6.0
        3  3.0  8.0
        4  4.0  6.0
        5  3.0  8.0

        >>> grouped.transform("mean")
            C        D
        0  3.666667  4.0
        1  4.000000  5.0
        2  3.666667  4.0
        3  4.000000  5.0
        4  3.666667  4.0
        5  4.000000  5.0

        The resulting dtype will reflect the return value of the passed ``func``,
        for example:

        >>> grouped.transform(lambda x: x.astype(int).max())
           C  D
        0  5  8
        1  5  9
        2  5  8
        3  5  9
        4  5  8
        5  5  9
        """
        return self._transform(
            func, *args, engine=engine, engine_kwargs=engine_kwargs, **kwargs
        )

Review comment (suggestion):
The column labels should be aligned to the right most character from the value.

```python
df = pd.DataFrame({"aa": [100, 100, 200], "bb": [300, 400, 500]})
print(df)
#     aa   bb
# 0  100  300
# 1  100  400
# 2  200  500
```


```suggestion
             C    D
        0  4.0  6.0
        1  3.0  8.0
        2  4.0  6.0
        3  3.0  8.0
        4  4.0  6.0
        5  3.0  8.0
```

Code after:
        ...         "A": ["foo", "bar", "foo", "bar", "foo", "bar"],
        ...         "B": ["one", "one", "two", "three", "two", "two"],
        ...         "C": [1, 5, 5, 2, 5, 5],
        ...         "D": [2.0, 5.0, 8.0, 1.0, 2.0, 9.0],
        ...     }
        ... )
        >>> grouped = df.groupby("A")[["C", "D"]]
        >>> grouped.transform(lambda x: (x - x.mean()) / x.std())
                  C         D
        0 -1.154701 -0.577350
        1  0.577350  0.000000
        2  0.577350  1.154701
        3 -1.154701 -1.000000
        4  0.577350 -0.577350
        5  0.577350  1.000000

        Broadcast result of the transformation

        >>> grouped.transform(lambda x: x.max() - x.min())
             C    D
        0  4.0  6.0
        1  3.0  8.0
        2  4.0  6.0
        3  3.0  8.0
        4  4.0  6.0
        5  3.0  8.0

        >>> grouped.transform("mean")
                  C    D
        0  3.666667  4.0
        1  4.000000  5.0
        2  3.666667  4.0
        3  4.000000  5.0
        4  3.666667  4.0
        5  4.000000  5.0

        The resulting dtype will reflect the return value of the passed ``func``,
        for example:

        >>> grouped.transform(lambda x: x.astype(int).max())
           C  D
        0  5  8
        1  5  9
        2  5  8
        3  5  9
        4  5  8
        5  5  9
        """
        return self._transform(
            func, *args, engine=engine, engine_kwargs=engine_kwargs, **kwargs
        )