Pandas 系列是帶有軸标簽的一維ndarray。标簽不必是唯一的,但必須是可哈希的類型。該對象同時支援基于整數和基于标簽的索引,并提供了許多方法來執行涉及索引的操作。
Pandas Series.mean()函數傳回給定Series對象中基礎資料的平均值。
用法: Series.mean(axis=None, skipna=None, level=None, numeric_only=None, **kwargs)
參數:
axis:要應用的功能的軸。
skipna:計算結果時排除NA /null值。
level:如果軸是MultiIndex(分層),則沿特定級别計數,并折疊成标量。
numeric_only:僅包括float,int,boolean列。
**kwargs:要傳遞給函數的其他關鍵字參數。
傳回:均值:标量或系列(如果指定級别)
範例1:采用Series.mean()函數查找給定系列對象中基礎資料的均值。
# importing pandas as pd
import pandas as pd
# Creating the Series
sr = pd.Series([10, 25, 3, 25, 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.mean()函數查找給定系列對象的均值。
# return the mean
result = sr.mean()
# Print the result
print(result)
輸出:
正如我們在輸出中看到的,Series.mean()函數已成功傳回給定系列對象的均值。
範例2:采用Series.mean()函數查找給定系列對象中基礎資料的均值。給定的系列對象還包含一些缺失值。
# importing pandas as pd
import pandas as pd
# Creating the Series
sr = pd.Series([19.5, 16.8, None, 22.78, 16.8, 20.124, None, 18.1002, 19.5])
# Print the series
print(sr)
輸出:
現在我們将使用Series.mean()函數查找給定系列對象的均值。我們将在計算均值時跳過所有缺失值。
# return the mean
# skip all the missing values
result = sr.mean(skipna = True)
# Print the result
print(result)
輸出:
正如我們在輸出中看到的,Series.mean()函數已成功傳回給定系列對象的均值。