Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
dataframe.mul() function return multiplication of dataframe and other element- wise. This function essentially does the same thing as the
dataframe * other, but it provides an additional support to handle missing values in one of the inputs.
Syntax: DataFrame.mul(other, axis=’columns’, level=None, fill_value=None)
other : Series, DataFrame, or constant
axis : For Series input, axis to match Series index on
level : Broadcast across a level, matching Index values on the passed MultiIndex level
fill_value : Fill existing missing (NaN) values, and any new element needed for successful DataFrame alignment, with this value before computation. If data in both corresponding DataFrame locations is missing the result will be missing
Returns : result : DataFrame
Example #1: Use
mul() function to find the multiplication of a dataframe with a series.
Note : For multiplication with series, dataframe axis used for multiplication must match series index on.
Let’s create the series
Lets use the
dataframe.mul() function to perform multiplication
Example #2: Use
mul() function to find the multiplication of two datframes. One dataframe contains
Lets use the
dataframe.mul() function to find the multiplication of two dataframes, also handle the missing values.
Notice, all the missing value cells has been filled with 100 before multiplication
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course