Python | Pandas Series.multiply ()

Python Methods and Functions

Series.multiply() Pandas Series.multiply() performs series multiplication and others, element by element. The operation is equivalent to series * other , but with support for fill_value replacement for missing data in one of the inputs.

Syntax: Series.multiply ( other, level = None, fill_value = None, axis = 0)

Parameter:
other: Series or scalar value
fill_value: Fill existing missing (NaN) value
level: Broadcast across a level,

Returns: result: Series

Example # 1: Use Series.multiply () to perform scalar multiplication with a given series object.

# import pandas as pd

import pandas as pd

  
# Create series < / p>

sr = pd.Series ([ 10 , 25 , 3 , 11 , 24 , 6 ])

 
# Create index

index_ = [ ' Coca Cola' , 'Sprite' , 'Coke' , ' Fanta' , 'Dew' , ' Thum bsUp' ]

 
# set index

sr.index = index_

 
# Print series

print (sr)

Output:

We will now use Series.multiply () to multiply the scalar by a series.

# multiply this value by row

result = sr.multiply ( other =   10 )

 
# Print result

print (result)

Output:

As we can see in the output, Series.multiply () returned the result of multiplying this scalar by a series object.

Example # 2: Use Series.multiply () to perform scalar multiplication with a given series object. This series object contains some missing values.

# import pandas as pd

import pandas as pd

 
# Create series

sr = pd.Series ([ 19.5 , 16.8 , None , 22.78 , None , 20.124 , None , 18.1002 , None ])

 
# Print series

print (sr)

Output:

We will now use Series.multiply () to multiply the scalar by the series.

# multiply the given value by a row
# fill in 5 for all missing values ​​

result = sr.multiply (other = 10 , fill_value = 5 )

 
# Print result

print (result)

Output:

As we can see in the output, Series.multiply () returned the result of multiplying this scalar by a series object.