在10个箱中将[0,1]范围内的值分离

时间:2017-11-28 13:04:51

标签: python pandas

data = pd.read_csv('C:\\User\\Desktop\\20_p_n1.csv',sep=',')
#print(data)
list = data['F'].tolist()
#print(list)
pd.qcut(list,10, labels=None, retbins=False, precision=1, duplicates='drop')

这里我已将数据帧转换为列表,以便将其传递给pd.qcut()。

这是我得到的输出。我的数据包含[0,1]之间的值,值为0.1,0.2,0.5等。但我只能生成一个类别。

[(-0.1, 1.0], (-0.1, 1.0], (-0.1, 1.0], (-0.1, 1.0], (-0.1, 1.0], ..., (-0.1, 1.0], (-0.1, 1.0], (-0.1, 1.0], (-0.1, 1.0], (-0.1, 1.0]]
Length: 25192
Categories (1, interval[float64]): [(-0.1, 1.0]]

data.head()

    F
0   0
1   0
2   0
3   0

pd.qcut output

data.head()

1 个答案:

答案 0 :(得分:0)

尝试使用pd.cut

[In] 1: pd.cut(np.random.rand(100), 10)

[Out]1: [(0.348, 0.38], (0.156, 0.188], (0.316, 0.348], (0.348, 0.38], (0.156, 0.188], (0.059, 0.0914], (0.348, 0.38], (0.156, 0.188], (0.348, 0.38], (0.284, 0.316]]
Categories (10, object): [(0.059, 0.0914] < (0.0914, 0.124] < (0.124, 0.156] < (0.156, 0.188] ... (0.252, 0.284] < (0.284, 0.316] < (0.316, 0.348] < (0.348, 0.38]]