code: def phonetic(s, method, concat=True, encoding='utf-8', decode_error='strict'):
      
  
      # encoding
      if sys.version_info[0] == 2:
          s = s.apply(
              lambda x: x.decode(encoding, decode_error)
              if type(x) == bytes else x)
  
      if concat:
          s = s.str.replace(r"[\-\_\s]", "")
  
      for alg in _phonetic_algorithms:
          if method in alg['argument_names']:
              phonetic_callback = alg['callback']
              break
      else:
          raise ValueError("The algorithm '{}' is not known.".format(method))
  
      return s.str.upper().apply(
          lambda x: phonetic_callback(x) if pandas.notnull(x) else np.nan
      )
docs: Convert names or strings into phonetic codes.
  
      The implemented algorithms are `soundex
      <https://en.wikipedia.org/wiki/Soundex>`_, `nysiis
      <https://en.wikipedia.org/wiki/New_York_State_Identification_and_
      Intelligence_System>`_, `metaphone
      <https://en.wikipedia.org/wiki/Metaphone>`_ or  `match_rating
      <https://en.wikipedia.org/wiki/Match_rating_approach>`_.
  
      Parameters
      ----------
      s : pandas.Series
          A pandas.Series with string values (often names) to encode.
      method: str
          The algorithm that is used to phonetically encode the values.
          The possible options are "soundex", "nysiis", "metaphone" or
          "match_rating".
      concat: bool, optional
          Remove whitespace before phonetic encoding.
      encoding: str, optional
          If bytes are given, this encoding is used to decode. Default
          is 'utf-8'.
      decode_error: {'strict', 'ignore', 'replace'}, optional
          Instruction on what to do if a byte Series is given that
          contains characters not of the given `encoding`. By default,
          it is 'strict', meaning that a UnicodeDecodeError will be
          raised. Other values are 'ignore' and 'replace'.
  
      Returns
      -------
      pandas.Series
          A Series with phonetic encoded values.