Change language

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.

Shop

Gifts for programmers

Learn programming in R: courses

$FREE
Gifts for programmers

Best Python online courses for 2022

$FREE
Gifts for programmers

Best laptop for Fortnite

$399+
Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best computer for crypto mining

$499+
Gifts for programmers

Best laptop for Sims 4

$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically