Pandas Series: dot() function
Compute the dot product between the Series and the columns in Pandas
The dot() function is used to compute the dot product between the Series and the columns of other.
This method computes the dot product between the Series and another one, or the Series and each columns of a DataFrame, or the Series and each columns of an array.
It can also be called using self @ other in Python >= 3.5.
Syntax:
Series.dot(self, other)
Parameters:
Name | Description | Type/Default Value | Required / Optional |
---|---|---|---|
other | The other object to compute the dot product with its columns. | Series, DataFrame or array-like | Required |
Returns: scalar, Series or numpy.ndarray
Return the dot product of the Series and other if other is a Series, the Series of the dot product of Series and each rows of other if other is a DataFrame or a numpy.ndarray between the Series and each columns of the numpy array.
Notes:
The Series and other has to share the same index if other is a Series or a DataFrame.
Example:
Python-Pandas Code:
import numpy as np
import pandas as pd
s = pd.Series([0, 2, 3, 4])
other = pd.Series([-2, 3, -4, 5])
s.dot(other)
Output:
14
Python-Pandas Code:
import numpy as np
import pandas as pd
s = pd.Series([0, 2, 3, 4])
other = pd.Series([-2, 3, -4, 5])
s @ other
Output:
14
Python-Pandas Code:
import numpy as np
import pandas as pd
s = pd.Series([0, 2, 3, 4])
other = pd.Series([-2, 3, -4, 5])
df = pd.DataFrame([[0, 2], [-3, 4], [5, -6], [7, 8]])
s.dot(df)
Output:
0 37 1 22 dtype: int64
Python-Pandas Code:
import numpy as np
import pandas as pd
s = pd.Series([0, 2, 3, 4])
other = pd.Series([-2, 3, -4, 5])
arr = np.array([[0, 2], [-3, 4], [5, -6], [7, 8]])
s.dot(arr)
Output:
array([37, 22], dtype=int64)
Previous: Product of the values for the requested Pandas axis
Next: Invoke a python function on values of Pandas series
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/pandas/series/series-dot.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics