code: def pivot(
      data: DataFrame,
      *,
      columns: IndexLabel,
      index: IndexLabel | lib.NoDefault = lib.no_default,
      values: IndexLabel | lib.NoDefault = lib.no_default,
  ) -> DataFrame:
      columns_listlike = com.convert_to_list_like(columns)
  
      # If columns is None we will create a MultiIndex level with None as name
      # which might cause duplicated names because None is the default for
      # level names
      data = data.copy(deep=False)
      data.index = data.index.copy()
      data.index.names = [
          name if name is not None else lib.no_default
          for name in data.index.names
      ]
  
      indexed: DataFrame | Series
      if values is lib.no_default:
          if index is not lib.no_default:
              cols = com.convert_to_list_like(index)
          else:
              cols = []
  
          append = index is lib.no_default
          # error: Unsupported operand types for + ("List[Any]" and "ExtensionArray")
          # error: Unsupported left operand type for + ("ExtensionArray")
          indexed = data.set_index(
              cols + columns_listlike,  # type: ignore[operator]
              append=append,
          )
      else:
          index_list: list[Index] | list[Series]
          if index is lib.no_default:
              if isinstance(data.index, MultiIndex):
                  # GH 23955
                  index_list = [
                      data.index.get_level_values(i)
                      for i in range(data.index.nlevels)
                  ]
              else:
                  index_list = [
                      data._constructor_sliced(
                          data.index, name=data.index.name
                      )
                  ]
          else:
              index_list = [
                  data[idx] for idx in com.convert_to_list_like(index)
              ]
  
          data_columns = [data[col] for col in columns_listlike]
          index_list.extend(data_columns)
          multiindex = MultiIndex.from_arrays(index_list)
  
          if is_list_like(values) and not isinstance(values, tuple):
              # Exclude tuple because it is seen as a single column name
              values = cast(Sequence[Hashable], values)
              indexed = data._constructor(
                  data[values]._values, index=multiindex, columns=values
              )
          else:
              indexed = data._constructor_sliced(
                  data[values]._values, index=multiindex
              )
      # error: Argument 1 to "unstack" of "DataFrame" has incompatible type "Union
      # [List[Any], ExtensionArray, ndarray[Any, Any], Index, Series]"; expected
      # "Hashable"
      # unstack with a MultiIndex returns a DataFrame
      result = cast("DataFrame", indexed.unstack(columns_listlike))  # type: ignore[arg-type]
      result.index.names = [
          name if name is not lib.no_default else None
          for name in result.index.names
      ]
  
      return result
  
imports: from __future__ import annotations
  from collections.abc import Hashable, Sequence
  from typing import TYPE_CHECKING, Callable, Literal, cast
  import warnings
  import numpy
  from pandas._libs import lib
  from pandas.util._decorators import Appender, Substitution
  from pandas.util._exceptions import find_stack_level
  from pandas.core.dtypes.cast import maybe_downcast_to_dtype
  from pandas.core.dtypes.common import is_list_like, is_nested_list_like, is_scalar
  from pandas.core.dtypes.dtypes import ExtensionDtype
  from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries
  import pandas.core.common
  from pandas.core.frame import _shared_docs
  from pandas.core.groupby import Grouper
  from pandas.core.indexes.api import Index, MultiIndex, get_objs_combined_axis
  from pandas.core.reshape.concat import concat
  from pandas.core.reshape.util import cartesian_product
  from pandas.core.series import Series
label_desc: Use image node_id 8 for calling a global function with example usage: pivot(data) and returns: result