Alignment via index labels
Alignment of Series
data by index labels is a fundamental concept in pandas, as well as being one of its most powerful concepts. Alignment provides automatic correlation of related values in multiple Series objects based upon index labels. This saves a lot of error-prone effort matching data in multiple sets using standard procedural techniques.
To demonstrate alignment, let's perform an example of adding values in two Series
objects. Let's start with the following two Series
objects representing two different samples of a set of variables (a
and b
):


Now suppose we would like to total the values for each variable. We can express this simply as s1 + s2
:

pandas has matched the measurement for each variable in each series, added those values, and returned us the sum for each in one succinct statement.
It is also possible to apply a scalar value to a Series
. The result will be that the scalar will be applied to each value in the Series
using the specified operation:

Remember...