Skip to content

DOC: Upgraded Docstring pandas.DataFrame.dot #23024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 19, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 49 additions & 4 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,16 +953,61 @@ def __len__(self):

def dot(self, other):
"""
Matrix multiplication with DataFrame or Series objects. Can also be
called using `self @ other` in Python >= 3.5.
Compute the matrix mutiplication between the DataFrame and other.

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

sorry I didn't see that before, for code we use double backticks (single backticks are for things we reference, like a function name, a class, a variable...)


Parameters
----------
other : DataFrame or Series
other : Series, DataFrame or array-like
The other object to compute the matrix product with.

Returns
-------
dot_product : DataFrame or Series
Series or DataFrame
Return the Series of the matrix product between the Dataframe and
other if other is a Series, the Dataframe of the matrix product of
each columns of the DataFrame/np.array and each columns of other
if other is a DataFrame or a numpy.ndarray.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rephrase this? Can't really understand it, we probably need to have more than one sentence.


See Also
--------
Series.dot: Compute the inner product of a Series with another Series
or the columns of a DataFrame or the columns of a numpy array.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you say instead "Same method for Series." or similar if that makes sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mind changing this?


Notes
-----
The dimensions of DataFrame and other must be compatible in order to
compute the matrix multiplication.

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

Examples
--------
>>> df = pd.DataFrame([[0, 1, -2, 3], [4, -5, 6, 7]])
>>> s = pd.Series([0, 1, 2, 3])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try to use smaller / easier values, so the math can be done mentally?

Also, avoid the print functions, the value will be shown without them too.

And divide the examples in groups with a blank line between them, and probably a short explanation of what you're doing would help reading.

>>> print(df.dot(s))
0 6
1 28
dtype: int64
>>> other = pd.DataFrame([[0, 1], [7, 8], [-6, 0], [-1, 2]])
>>> print(df.dot(other))
0 1
0 16 14
1 -78 -22
>>> df @ other
0 1
0 16 14
1 -78 -22
>>> arr = np.array([[0, 1], [-2, 3], [4, -5], [6, 7]])
>>> print(df.dot(arr))
0 1
0 8 34
1 76 8
"""
if isinstance(other, (Series, DataFrame)):
common = self.columns.union(other.index)
Expand Down