Can anybody help me understand the difference (if any) between the two methods: df.mul
and df.rmul
? The documentation looks identical:
docs for mul
docs for rmul
The mul() method multiplies each value in the DataFrame with a specified value. The specified value must be an object that can be multiplied with the values of the DataFrame.
The mul() method of DataFrame object multiplies the elements of a DataFrame object with another DataFrame object, series or any other Python sequence. mul() does an elementwise multiplication of a DataFrame with another DataFrame, a pandas Series or a Python Sequence.
The dot() method of pandas DataFrame class does a matrix multiplication between a DataFrame and another DataFrame, a pandas Series or a Python sequence and returns the resultant matrix.
The documentation is not identical. As stated in the documentation, df.mul(other)
is equivalent to df * other
, while df.rmul(other)
is equivalent to other * df
.
This probably doesn't matter for most cases, but it will matter if, e.g., you have a dataframe of object dtype whose elements have noncommutative multiplication. Maybe you wrote a quaternion class and filled a dataframe with quaternions. Someone with more Pandas experience might be able to come up with more practical cases where it matters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With