code: def transform_column(
      df: pd.DataFrame,
      column_name: Hashable,
      function: Callable,
      dest_column_name: Optional[str] = None,
      elementwise: bool = True,
  ) -> pd.DataFrame:
      """Transform the given column using the provided function.
  
      Meant to be the method-chaining equivalent of:
      ```python
      df[dest_column_name] = df[column_name].apply(function)
      ```
  
      Functions can be applied in one of two ways:
  
      - **Element-wise** (default; `elementwise=True`). Then, the individual
      column elements will be passed in as the first argument of `function`.
      - **Column-wise** (`elementwise=False`). Then, `function` is expected to
      take in a pandas Series and return a sequence that is of identical length
      to the original.
  
      If `dest_column_name` is provided, then the transformation result is stored
      in that column. Otherwise, the transformed result is stored under the name
      of the original column.
  
      This method does not mutate the original DataFrame.
  
      Examples:
          Transform a column in-place with an element-wise function.
  
          >>> import pandas as pd
          >>> import janitor
          >>> df = pd.DataFrame({
          ...     "a": [2, 3, 4],
          ...     "b": ["area", "pyjanitor", "grapefruit"],
          ... })
          >>> df
             a           b
          0  2        area
          1  3   pyjanitor
          2  4  grapefruit
          >>> df.transform_column(
          ...     column_name="a",
          ...     function=lambda x: x**2 - 1,
          ... )
              a           b
          0   3        area
          1   8   pyjanitor
          2  15  grapefruit
  
      Examples:
          Transform a column in-place with an column-wise function.
  
          >>> df.transform_column(
          ...     column_name="b",
          ...     function=lambda srs: srs.str[:5],
          ...     elementwise=False,
          ... )
             a      b
          0  2   area
          1  3  pyjan
          2  4  grape
  
      Args:
          df: A pandas DataFrame.
          column_name: The column to transform.
          function: A function to apply on the column.
          dest_column_name: The column name to store the transformation result
              in. Defaults to None, which will result in the original column
              name being overwritten. If a name is provided here, then a new
              column with the transformed values will be created.
          elementwise: Whether to apply the function elementwise or not.
              If `elementwise` is True, then the function's first argument
              should be the data type of each datum in the column of data,
              and should return a transformed datum.
              If `elementwise` is False, then the function's should expect
              a pandas Series passed into it, and return a pandas Series.
  
      Returns:
          A pandas DataFrame with a transformed column.
      """
      check_column(df, column_name)
  
      if dest_column_name is None:
          dest_column_name = column_name
      elif dest_column_name != column_name:
          # If `dest_column_name` is provided and equals `column_name`, then we
          # assume that the user's intent is to perform an in-place
          # transformation (Same behaviour as when `dest_column_name` = None).
          # Otherwise we throw an error if `dest_column_name` already exists in
          # df.
          check_column(df, dest_column_name, present=False)
  
      result = _get_transform_column_result(
          df[column_name],
          function,
          elementwise,
      )
  
      return df.assign(**{dest_column_name: result})
  
imports: from typing import Callable, Dict, Hashable, List, Optional, Tuple, Union
  import pandas
  import pandas_flavor
  from janitor.utils import check, check_column, deprecated_alias
label_desc: Use image node_id 2 for calling a global function with example usage: transform_column(df, column_name, function, dest_column_name, elementwise) and returns: df