code: def pivot(data, index=None, columns=None, values=None):
      if values is None:
          cols = [columns] if index is None else [index, columns]
          append = index is None
          indexed = data.set_index(cols, append=append)
      else:
          if index is None:
              index = data.index
          else:
              index = data[index]
          index = MultiIndex.from_arrays([index, data[columns]])
  
          if is_list_like(values) and not isinstance(values, tuple):
              # Exclude tuple because it is seen as a single column name
              indexed = data._constructor(
                  data[values].values, index=index, columns=values
              )
          else:
              indexed = data._constructor_sliced(
                  data[values].values, index=index
              )
      return indexed.unstack(columns)
  
imports: import numpy
  from pandas.compat import lrange, range, zip
  from pandas.util._decorators import Appender, Substitution
  from pandas.core.dtypes.cast import maybe_downcast_to_dtype
  from pandas.core.dtypes.common import is_integer_dtype, is_list_like, is_scalar
  from pandas.core.dtypes.generic import ABCDataFrame, ABCSeries
  from pandas import compat
  import pandas.core.common
  from pandas.core.frame import _shared_docs
  from pandas.core.groupby import Grouper
  from pandas.core.index 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 7 for calling a global function with example usage: pivot(data, index, columns, values) and returns: indexed