Python | Pandas Dataframe / Series.dot ()



Pandas Dataframe.dot() works similarly to the mul () method, but instead of returning the multiplied individual values, the Dot product is returned (the sum of the multiplication of values ​​for each index).

Syntax: Series.dot (other)
Parameters:
other: Other Series to be used to calculate DOT product

Return type: Series with updated values ​​

Example # 1:
This example creates two series from Python lists using the Pandas Series () method. Then the method for series1 is called and series2 is passed as a parameter. The result is then stored in a variable and displayed.

# pandas module import

import pandas as pd 

 
# numpy module import

import numpy as np 

 
# create series 1

series1 = pd.Series ([ 7 , 5 , 6 , 4 , 9 ]) 

  
# creating series 2

series2 = pd.Series ([ 1 , 2 , 3 , 10 , 2 ]) 

 
# saving in a new variable
# calling the .dot () method

ans = series1.dot (series2)

 
# display

print ( `Dot product = {}` . format (ans))

Exit :

 Dot product = 93 

Explanation —
The items in the caller series are multiplied by the items with the same index in the skipped series. All of the multiplied values ​​are then added to get the dot product. 
As in the above example, the series:

 [7, 5, 6, 4, 9] [1, 2, 3, 10, 2] Dot product = 7 * 1 + 5 * 2 + 6 * 3 + 4 * 10 + 9 * 2 = 7 + 10 + 18 + 40 + 18 = 93 

Note. If there is any -or Null, the net result is NaN. NaN values ​​should be dropped / replaced using fillna () respectively.