Renaming

In this Section, we will cover the most common scenarios for column renaming which are:

  • Mapping Names: This is the most common scenario for renaming columns. In this approach, we provide a mapping from the old column names to the new names for the columns whose names we wish to change.
  • Setting Names: We can set the names of columns based on their position (order) in the data frame.
  • Adding Suffix or Prefix: We can add a specific string as a suffix or prefix to all column names.
  • Standardize Names: The original column names of a data frame may not conform to best practices, for example, they may contain spaces or unconventional special characters. In this section, we show how to change the column names to have them conform to a standard naming convention. In particular, snake_case or camelCase.
  • Implicit Renaming: We may wish to apply some string manipulation function on the current column names to generate the desired column names. Cleaning column names is a common application of implicit renaming.
  • Dynamic Renaming: We wish to specify aspects of column renaming dynamically i.e. through environment variables or function arguments. For instance, we wish to pass to a function the names of columns to be renamed. This is especially useful when creating reusable functions of packages.
PYTHON
I/O