Renaming column names
One of the most common operations on a DataFrame is to rename the column names. I like to rename my columns so that they are also valid Python attribute names. This means that they do not start with numbers and are lowercased alphanumerics with underscores. Good column names should also be descriptive, brief, and not clash with existing DataFrame or Series attributes.
In this recipe, the column names are renamed. The motivation for renaming is to make your code easier to understand, and also let your environment assist you. Recall that Jupyter will allow you to complete Series methods if you accessed the Series using dot notation (but will not allow method completion on index access).
How to do it…
- Read in the movie dataset, and make the index meaningful by setting it as the movie title:
>>> movies = pd.read_csv("data/movie.csv")
- The renamed DataFrame method accepts dictionaries that map the old...