📜  Python|熊猫系列.product()

📅  最后修改于: 2022-05-13 01:54:55.021000             🧑  作者: Mango

Python|熊猫系列.product()

Pandas 系列是带有轴标签的一维 ndarray。标签不必是唯一的,但必须是可散列的类型。该对象支持基于整数和基于标签的索引,并提供了许多用于执行涉及索引的操作的方法。

Pandas Series.product()函数返回给定 Series 对象中基础数据的乘积。

示例 #1:使用Series.product()函数查找给定 Series 对象中基础数据的乘积。

# importing pandas as pd
import pandas as pd
  
# Creating the Series
sr = pd.Series([10, 25, 3, 11, 24, 6])
  
# Create the Index
index_ = ['Coca Cola', 'Sprite', 'Coke', 'Fanta', 'Dew', 'ThumbsUp']
  
# set the index
sr.index = index_
  
# Print the series
print(sr)

输出 :

现在我们将使用Series.product()函数来查找给定系列对象中元素的乘积。

# return the product of all elements
result = sr.product()
  
# Print the result
print(result)

输出 :

正如我们在输出中看到的, Series.product()函数已成功返回给定系列对象中基础数据的乘积。

示例 #2:使用Series.product()函数查找给定 Series 对象中基础数据的乘积。给定的系列对象中包含一些缺失值。

# importing pandas as pd
import pandas as pd
  
# Creating the Series
sr = pd.Series([19.5, 16.8, None, 22.78, None, 20.124, None, 18.1002, None])
  
# Print the series
print(sr)

输出 :

现在我们将使用Series.product()函数来查找给定系列对象中元素的乘积。我们将跳过缺失值。

# return the product of all elements
result = sr.product(skipna = True)
  
# Print the result
print(result)

输出 :

正如我们在输出中看到的, Series.product()函数已成功返回给定系列对象中基础数据的乘积。