df["A"].value_counts()
(25.0, 38.0] 361594
(12.999, 25.0] 330552
(55.0, 218.0] 305439
(38.0, 55.0] 231683
Name: A, dtype: int64
我们有下面的间隔,每当新的数据点到来时,我需要映射到下面的上面的间隔。我想要这样的东西。
def func_(x):
if (x> 12.999) & (x< 25.0):
return (12.999, 25.0]
elif:
for rest of bucket range
您可以按CategoricalIndex.categories
:生成的类别重用bins
参数
s = df["A"].value_counts()
print (pd.cut(df['new'], bins=s.index.categories))