code: def duplicated(self, subset=None, keep='first'):
          
          from pandas.core.sorting import get_group_index
          from pandas._libs.hashtable import duplicated_int64, _SIZE_HINT_LIMIT
  
          if self.empty:
              return Series(dtype=bool)
  
          def f(vals):
              labels, shape = algorithms.factorize(
                  vals, size_hint=min(len(self), _SIZE_HINT_LIMIT))
              return labels.astype('i8', copy=False), len(shape)
  
          if subset is None:
              subset = self.columns
          elif (not np.iterable(subset) or
                isinstance(subset, str) or
                isinstance(subset, tuple) and subset in self.columns):
              subset = subset,
  
          # Verify all columns in subset exist in the queried dataframe
          # Otherwise, raise a KeyError, same as if you try to __getitem__ with a
          # key that doesn't exist.
          diff = Index(subset).difference(self.columns)
          if not diff.empty:
              raise KeyError(diff)
  
          vals = (col.values for name, col in self.iteritems()
                  if name in subset)
          labels, shape = map(list, zip(*map(f, vals)))
  
          ids = get_group_index(labels, shape, sort=False, xnull=False)
          return Series(duplicated_int64(ids, keep), index=self.index)
docs: Return boolean Series denoting duplicate rows, optionally only
          considering certain columns.
  
          Parameters
          ----------
          subset : column label or sequence of labels, optional
              Only consider certain columns for identifying duplicates, by
              default use all of the columns
          keep : {'first', 'last', False}, default 'first'
              - ``first`` : Mark duplicates as ``True`` except for the
                first occurrence.
              - ``last`` : Mark duplicates as ``True`` except for the
                last occurrence.
              - False : Mark all duplicates as ``True``.
  
          Returns
          -------
          Series