Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas: df.mul vs df.rmul

Tags:

python

pandas

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

like image 894
FLab Avatar asked Aug 09 '16 17:08

FLab


People also ask

What does MUL do in Python?

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.

How do you multiply two pandas DataFrames?

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.

How do pandas multiply matrices?

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.


1 Answers

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.

like image 64
user2357112 supports Monica Avatar answered Oct 19 '22 04:10

user2357112 supports Monica