I think the transition from reset_index()
is a way, but it is possible to drop the index, rather than returning it back to the dataframe.
Like this:
s1 = pd.Series([1,2,3,4,5,6,7], index=[52,34,3,53,636,7,4]) 52 1 34 2 3 3 53 4 636 5 7 6 4 7 dtype: int64 s1.reset_index(drop=True) 0 1 1 2 2 3 3 4 4 5 5 6 6 7 dtype: int64
The reason I support the reset_index()
approach over the other proposed approach with simple multiplication by values
s1 * s2.values
lies in the fact that this is not very explicit. This line does not tell me that there is an index problem that you are solving.
This line says very clearly that you are solving the index problem:
s1.reset_index(drop=True) * s2.reset_index(drop=True)
Or split it into several lines:
s1.reset_index(inplace=True, drop=True) s2.reset_index(inplace=True, drop=True) s1 * s2
source share