Transformations: How to Do Them

How do we perform transformations on a DataFrame?

Answer

As we said before, we use vectorization through "vectorized syntax" and through built in functions. These are fast and efficient.

Below are common examples of transformations:

Python
# Vectorized Syntax
df["Calories"] + 5                   
np.sqrt(df)                 
(df - np.mean(df) / np.std(df))   # works because of broadcasting

# Built-in functions
df["Name"].str.upper()     # more on vectorized string functions later   
df["Name"].str.capitalize()
Back to collection