Exploding indexes
The previous recipe walked through a trivial example of two small Series being added together with unequal indexes. This recipe is more of an "anti-recipe" of what not to do. The Cartesian product of index alignment can produce comically incorrect results when dealing with larger amounts of 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.
How to do it…
- Read in the employee data and set the index to the
RACE
column:>>> employee = pd.read_csv( ... "data/employee.csv", index_col="RACE" ... ) >>> employee.head() UNIQUE_ID POSITION_TITLE ... HIRE_DATE JOB_DATE RACE ... Hispanic/... 0 ASSISTAN... ... 2006-06-12 2012-10-13 Hispanic/... 1 LIBRARY ... ...