也许您正在寻找pandas.cut:
import pandas as pdimport numpy as npdf = pd.Dataframe(np.arange(50), columns=['filtercol'])filter_values = [0, 5, 17, 33] out = pd.cut(df.filtercol, bins=filter_values)counts = pd.value_counts(out)# counts is a Seriesprint(counts)
产量
(17, 33] 16(5, 17] 12(0, 5] 5
要对结果重新排序以使bin范围按顺序显示,您可以使用
counts.sort_index()
产生
(0, 5] 5(5, 17] 12(17, 33] 16
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)