【发布时间】:2020-05-14 09:23:32
【问题描述】:
我正在为一个建模项目分箱,但遇到了这个问题。 此示例使用不带 11 的数据帧获取 bin,当 bin 应用于其中包含 11 的新数据帧时,这会导致 NaN。显然这会发生,但我想知道是否有(通常有)任何聪明的方法可以轻松处理这个问题,例如将 (7.75, 10.0] 转换为 (7.75, np.inf) 的一些技术。
import pandas as pd
a,bin = pd.qcut(pd.DataFrame({"A":[1,2,3,4,5,6,7,8,9,10]}).A,retbins = True, q = 4)
pd.cut(pd.DataFrame({"A":[1,2,11]}).A, bins = bin ,include_lowest = True)
0 (0.999, 3.25]
1 (0.999, 3.25]
2 NaN
Name: A, dtype: category
Categories (4, interval[float64]): [(0.999, 3.25] < (3.25, 5.5] < (5.5, 7.75] < (7.75, 10.0]]
【问题讨论】:
标签: python pandas dataframe feature-engineering