Changing Series values
During the data cleaning process, we often need to change the values in a data Series or create a new one. We can change all the values in a Series, or just the values in a subset of our data. Most of the techniques we have been using to get values from a Series can be used to update Series values, though some minor modifications are necessary.
Getting ready
We will work with the overall high school GPA column from the NLS in this recipe.
How to do it…
We can change the values in a pandas Series for all rows, as well as for selected rows. We can update a Series with scalars by performing arithmetic operations on other Series, and by using summary statistics. Let’s take a look at this:
- Import
pandas
and load the NLS data:import pandas as pd nls97 = pd.read_csv("data/nls97f.csv", low_memory=False) nls97.set_index("personid", inplace=True)
- Edit all the values based on a scalar. ...