Exploding indexes
The previous recipe walked through a trivial example of two small Series being added together with unequal indexes. This problem can produce comically incorrect results when dealing with larger data.
Getting ready
In this recipe, we add two larger Series that have indexes with only a few unique values but in different orders. The result will explode the number of values in the indexes.
How to do it...
- Read in the employee data and set the index equal to the race column:
>>> employee = pd.read_csv('data/employee.csv', index_col='RACE') >>> employee.head()
- Select the
BASE_SALARY
column as two different Series. Check to see whether this operation actually did create two new objects:
>>> salary1 = employee['BASE_SALARY'] >>> salary2 = employee['BASE_SALARY'] >>> salary1 is salary2 True
- The
salary1
andsalary2
variables are actually referring to the same object. This means that any change to one will change the other. To ensure that you receive...