Computer >> Máy Tính >  >> Lập trình >> Python

In giá trị trung bình của một chuỗi Gấu trúc

Hàm mean () trong thư viện Pandas có thể được sử dụng để tìm giá trị trung bình của một chuỗi.

Thuật toán

Step 1: Define a Pandas series.
Step 2: Use the mean() function to calculate the mean.
Step 3: Print the mean.

Mã mẫu

import pandas as pd

series = pd.Series([10,20,30,40,50])
print("Pandas Series: \n", series)

series_mean = series.mean()
print("Mean of the Pandas series:\n", series_mean)

Đầu ra

Pandas Series:
0    10
1    20
2    30
3    40
4    50
dtype: int64
Mean of the Pandas series:
30.0