Skip to content

Commit 0a29896

Browse files
HubertKljreback
authored andcommitted
DOC: Upgraded Docstring pandas.DataFrame.dot (#23024)
1 parent c53f56b commit 0a29896

File tree

1 file changed

+58
-4
lines changed

1 file changed

+58
-4
lines changed

pandas/core/frame.py

+58-4
Original file line numberDiff line numberDiff line change
@@ -931,16 +931,70 @@ def __len__(self):
931931

932932
def dot(self, other):
933933
"""
934-
Matrix multiplication with DataFrame or Series objects. Can also be
935-
called using `self @ other` in Python >= 3.5.
934+
Compute the matrix mutiplication between the DataFrame and other.
935+
936+
This method computes the matrix product between the DataFrame and the
937+
values of an other Series, DataFrame or a numpy array.
938+
939+
It can also be called using ``self @ other`` in Python >= 3.5.
936940
937941
Parameters
938942
----------
939-
other : DataFrame or Series
943+
other : Series, DataFrame or array-like
944+
The other object to compute the matrix product with.
940945
941946
Returns
942947
-------
943-
dot_product : DataFrame or Series
948+
Series or DataFrame
949+
If other is a Series, return the matrix product between self and
950+
other as a Serie. If other is a DataFrame or a numpy.array, return
951+
the matrix product of self and other in a DataFrame of a np.array.
952+
953+
See Also
954+
--------
955+
Series.dot: Similar method for Series.
956+
957+
Notes
958+
-----
959+
The dimensions of DataFrame and other must be compatible in order to
960+
compute the matrix multiplication.
961+
962+
The dot method for Series computes the inner product, instead of the
963+
matrix product here.
964+
965+
Examples
966+
--------
967+
Here we multiply a DataFrame with a Series.
968+
969+
>>> df = pd.DataFrame([[0, 1, -2, -1], [1, 1, 1, 1]])
970+
>>> s = pd.Series([1, 1, 2, 1])
971+
>>> df.dot(s)
972+
0 -4
973+
1 5
974+
dtype: int64
975+
976+
Here we multiply a DataFrame with another DataFrame.
977+
978+
>>> other = pd.DataFrame([[0, 1], [1, 2], [-1, -1], [2, 0]])
979+
>>> df.dot(other)
980+
0 1
981+
0 1 4
982+
1 2 2
983+
984+
Note that the dot method give the same result as @
985+
986+
>>> df @ other
987+
0 1
988+
0 1 4
989+
1 2 2
990+
991+
The dot method works also if other is an np.array.
992+
993+
>>> arr = np.array([[0, 1], [1, 2], [-1, -1], [2, 0]])
994+
>>> df.dot(arr)
995+
0 1
996+
0 1 4
997+
1 2 2
944998
"""
945999
if isinstance(other, (Series, DataFrame)):
9461000
common = self.columns.union(other.index)

0 commit comments

Comments
 (0)