📜  Python|熊猫系列.product()(1)

📅  最后修改于: 2023-12-03 15:19:21.899000             🧑  作者: Mango

Python Pandas Series.product()

The product() method in Pandas Series object is used to return the product of all the elements in the Series.

Syntax
Series.product(skipna=None, axis=None, level=None, numeric_only=None, min_count=0)
Parameters

The following parameters can be used along with the product() method:

  • skipna: This parameter is used to exclude the NA/null values. The default value is None which includes all the NaN values in calculation.
  • axis: This parameter is used to compute the product along a specific axis. The default value is None which calculates the product of all the elements.
  • level: This parameter is used to specify the level for the multi-index. The default value is None.
  • numeric_only: This parameter is used to include only float, int or boolean types in the calculation. The default value is None which means it will include all the types.
  • min_count: This parameter is used to set the minimum number of non-NA/null values required for the calculation. The default value is 0.
Return Value

The method returns the product of all the non-NA/null values of the Pandas Series. If the Series object is empty, it returns a value of 1.

Example
import pandas as pd

s = pd.Series([1, 2, 3, 4, 5])
print("Series:")
print(s)

print("\nProduct of all elements in the series:")
print(s.product())

Output:

Series:
0    1
1    2
2    3
3    4
4    5
dtype: int64

Product of all elements in the series:
120

Here, we have created a Pandas Series object s and applied the product() method to calculate the product of all its elements. The output shows the product as 120.

Conclusion

The product() method in Pandas Series object is a useful function to calculate the product of all the elements in the Series. The method provides various parameters to customize the calculation according to specific needs.