Pandas DataFrame dot() Method
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.
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.