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.
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.
- 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()
>>> 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...