code: def generalize_names_duplcheck(df, col_name):
      """Generalizes names and removes duplicates.
  
      Description : Applies mlxtend.text.generalize_names to a DataFrame
      with 1 first name letter by default
      and uses more first name letters if duplicates are detected.
  
      Parameters
      ----------
      df : `pandas.DataFrame`
          DataFrame that contains a column where
          generalize_names should be applied.
      col_name : `str`
          Name of the DataFrame column where `generalize_names`
          function should be applied to.
  
      Returns
      ----------
      df_new : `str`
          New DataFrame object where generalize_names function has
          been applied without duplicates.
  
      Examples
      -----------
      For usage examples, please see
      https://rasbt.github.io/mlxtend/user_guide/text/generalize_names_duplcheck/
  
      """
      df_new = df.copy()
  
      df_new.drop_duplicates(subset=[col_name], inplace=True)
  
      df_new[col_name] = df_new[col_name].apply(generalize_names)
  
      if Version(pandas_version) < Version("0.17"):
          dupl = list(
              df_new[
                  df_new.duplicated(subset=col_name, keep="last")
              ].index
          ) + list(
              df_new[
                  df_new.duplicated(subset=col_name, keep="first")
              ].index
          )
      else:
          dupl = list(
              df_new[
                  df_new.duplicated(subset=col_name, keep="last")
              ].index
          ) + list(
              df_new[
                  df_new.duplicated(subset=col_name, keep="first")
              ].index
          )
  
      firstname_letters = 2
      while len(dupl) > 0:
          for idx in dupl:
              df_new.loc[idx, col_name] = generalize_names(
                  df.loc[idx, col_name],
                  firstname_output_letters=firstname_letters,
              )
          if Version(pandas_version) < Version("0.17"):
              dupl = list(
                  df_new[
                      df_new.duplicated(subset=col_name, keep="last")
                  ].index
              ) + list(
                  df_new[
                      df_new.duplicated(subset=col_name, keep="first")
                  ].index
              )
          else:
              dupl = list(
                  df_new[
                      df_new.duplicated(subset=col_name, keep="last")
                  ].index
              ) + list(
                  df_new[
                      df_new.duplicated(subset=col_name, keep="first")
                  ].index
              )
          firstname_letters += 1
      return df_new
  
file_path: mlxtend/mlxtend/text/names.py
imports: import re
  import string
  import sys
  import unicodedata
  from packaging.version import Version
  from pandas import __version__
label_desc: Use image node_id 2 for calling a global function with example usage: generalize_names_duplcheck(df, col_name) and returns: df_new