需要借助pandas库的between()函数:
示例代码import numpy as np import pandas as pd array = np.array([1, 2, 3, 4, 5, 5, 6, 7, 8]) series = pd.Series(array) is_between = series.between(2, 5) # 规定范围[2,5],注意是闭区间 between_rate = is_between.sum() / len(series) print("在范围内的比例:", between_rate)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)