Python|熊猫系列.prod()
Python是一种用于进行数据分析的出色语言,主要是因为以数据为中心的Python包的奇妙生态系统。 Pandas就是其中之一,它使导入和分析数据变得更加容易。
Pandas Series.prod()
方法用于获取请求轴的值的乘积。
Syntax: Series.prod(axis=None, skipna=None, level=None, numeric_only=None, min_count=0)
Parameters:
axis : {index (0)}
skipna[boolean, default True] : Exclude NA/null values. If an entire row/column is NA, the result will be NA
level[int or level name, default None] : If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a scalar.
numeric_only[boolean, default None] : Include only float, int, boolean data. If None, will attempt to use everything, then use only numeric data
Returns: Return the product of the values for the requested axis
代码 #1:默认情况下,空系列或全 NA 系列的乘积为 1。
# importing pandas module
import pandas as pd
# min_count = 0 is the default
pd.Series([]).prod()
# When passed min_count = 1,
# product of an empty series will be NaN
pd.Series([]).prod(min_count = 1)
输出:
1.0
nan
代码#2:
# importing pandas module
import pandas as pd
# applying prod() on a list of series
val = pd.Series([12, 5, 7]).prod()
val
输出:
420