pandas 1.4.2

NotesParametersReturnsBackRef
dot(self, other: 'AnyArrayLike | DataFrame') -> 'DataFrame | Series'

This method computes the matrix product between the DataFrame and the values of an other Series, DataFrame or a numpy array.

It can also be called using self @ other in Python >= 3.5.

Notes

The dimensions of DataFrame and other must be compatible in order to compute the matrix multiplication. In addition, the column names of DataFrame and the index of other must contain the same values, as they will be aligned prior to the multiplication.

The dot method for Series computes the inner product, instead of the matrix product here.

Parameters

other : Series, DataFrame or array-like

The other object to compute the matrix product with.

Returns

Series or DataFrame

If other is a Series, return the matrix product between self and other as a Series. If other is a DataFrame or a numpy.array, return the matrix product of self and other in a DataFrame of a np.array.

Compute the matrix multiplication between the DataFrame and other.

See Also

Series.dot

Similar method for Series.

Examples

Here we multiply a DataFrame with a Series.

This example is valid syntax, but we were not able to check execution
>>> df = pd.DataFrame([[0, 1, -2, -1], [1, 1, 1, 1]])
... s = pd.Series([1, 1, 2, 1])
... df.dot(s) 0 -4 1 5 dtype: int64

Here we multiply a DataFrame with another DataFrame.

This example is valid syntax, but we were not able to check execution
>>> other = pd.DataFrame([[0, 1], [1, 2], [-1, -1], [2, 0]])
... df.dot(other) 0 1 0 1 4 1 2 2

Note that the dot method give the same result as @

This example is valid syntax, but we were not able to check execution
>>> df @ other
    0   1
0   1   4
1   2   2

The dot method works also if other is an np.array.

This example is valid syntax, but we were not able to check execution
>>> arr = np.array([[0, 1], [1, 2], [-1, -1], [2, 0]])
... df.dot(arr) 0 1 0 1 4 1 2 2

Note how shuffling of the objects does not change the result.

This example is valid syntax, but we were not able to check execution
>>> s2 = s.reindex([1, 0, 2, 3])
... df.dot(s2) 0 -4 1 5 dtype: int64
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.series.Series.dot

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/frame.py#1427
type: <class 'function'>
Commit: