import re
import functools


def rename_column_headers(df, pattern,
                          repl):
  """Renames column headers of dataframe by regex replacement.

  Args:
    df: A pandas dataframe.
    pattern: Regex pattern to replace.
    repl: Replacement string to insert where old string was.

  Returns:
    Dataframe with renamed columns.
  """

  def _regex_replace_fn(x, pattern, repl):
    return re.sub(pattern=pattern, repl=repl, string=x)

  return df.rename(
      columns=functools.partial(_regex_replace_fn, pattern=pattern, repl=repl))