Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

Pandas DataFrame dot() Method

❮ DataFrame Reference


Example

Multiply values from one DataFrame with values from another DataFrame, and add them together:

import pandas as pd

df1 = pd.DataFrame([[1, 2], [3, 4]])
df2 = pd.DataFrame([[5, 6], [7, 8]])

print(df1.dot(df2))
Try it Yourself »

Definition and Usage

The dot() method multiplies each value from one DataFrame with the values from another DataFrame (or Series or array), and adds them together.

Example Explained:

Assume you have these two DataFrame objects:

[[1, 2], [3, 4]]

[[5, 6], [7, 8]]

Multiply the values from the first DataFrame with the values from the second DataFrame, one by one like this:

1 * 5 = 5
2 * 7 = 14

Summarize the two products:

5 + 14 = 19

19 will be the first value in the result.

Here you can see the calculation for each value in the result:

(1 * 5) + (2 * 7) = 19
(1 * 6) + (2 * 8) = 22
(3 * 5) + (4 * 7) = 43
(3 * 6) + (4 * 8) = 50

which will result in a DataFrame object like this::

[[19, 22], [43, 50]]

Syntax

dataframe.dot(other)

Parameters

Parameter Description
other Required. A number, list of numbers, or another object with a data structure that fits with the original DataFrame.

Return Value

A DataFrame with the results.


❮ DataFrame Reference

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.