code: def mean_target(df, feature_name, target_name, C=None):
      
  
      def group_mean(group):
          group_size = float(group.shape[0])
          if C is None:
              return (group.mean() * group_size + global_mean) / group_size
          else:
              return (group.mean() * group_size + global_mean * C) / (group_size + C)
  
      global_mean = df[target_name].mean()
      return df.groupby(feature_name)[target_name].transform(group_mean)
docs: Mean target.
      Original idea: Stanislav Semenov
  
      Parameters
      ----------
      C : float, default None
          Regularization coefficient. The higher, the more conservative result.
          The optimal value lies between 10 and 50 depending on the data.
      feature_name : str
      target_name : str
      df: DataFrame
  
      Returns
      -------
      Series