Manipulation Methods

Learn data manipulation methods in this lesson.

We consider manipulation methods to be the workhorses of pandas. When we have a dataset that we’re trying to understand, clean up, and model, we use methods that operate on a Series and return a new Series (usually with the same index) to stick it back in the DataFrame we’re working on. Most of the methods we discuss here manipulate the Series values but preserve the index.

Manipulating data using .apply

The .apply is a curious method, and often it’s recommended to avoid it, but sometimes it comes in handy. This method allows us to apply a function element-wise to every value. If we pass in a NumPy function that works on an array, it will broadcast the operation to the Series.

However, usually, when we see this method in use, it’s a code smell. How so? Because the .apply method ...