我的第一行代码是:
sbins ,bin_bounds = pd.qcut(df_new_sample.index, 3, labels=list('ABC'),retbins=True)
用来创建这样的数据框:
timestamp topAsk topBid CPA midprice CPB spread gamma_perc spread_bin
0 2018-10-25 14:17:00 0.00420001 0.00420000 0.00420001 0.00420000 0.00420000 1E-8 0.000000 A
39369 2018-10-18 09:11:00 0.00426123 0.00425517 0.00425823 0.00425820 0.00425820 0.00000606 0.000000 B
39374 2018-10-17 23:30:00 0.00435109 0.00434503 0.00435109 0.00434806 0.00434806 0.00000606 0.000000 B
39376 2018-10-25 09:34:00 0.00415542 0.00414936 0.00415239 0.00415239 0.00415239 0.00000606 0.000000 B
39377 2018-10-15 15:05:00 0.00350000 0.00349394 0.00350272 0.00349697 0.00349697 0.00000606 0.000000 B
39380 2018-10-22 13:37:00 0.00436453 0.00435847 0.00436623 0.00436150 0.00436150 0.00000606 0.000000 B
39382 2018-11-15 21:43:00 0.00313878 0.00313272 0.00313585 0.00313575 0.00313575 0.00000606 0.000000 B
39384 2018-11-08 12:24:00 0.00356642 0.00356036 0.00356339 0.00356339 0.00356339 0.00000606 0.000000 B
39386 2018-11-27 20:09:00 0.00331422 0.00330816 0.00331120 0.00331119 0.00331119 0.00000606 0.000000 B
39387 2018-10-04 02:26:00 0.00277023 0.00276417 0.00276720 0.00276720 0.00276720 0.00000606 0.000000 B
39391 2018-11-03 23:22:00 0.00399797 0.00399191 0.00399494 0.00399494 0.00399494 0.00000606 0.000000 B
39394 2018-11-18 21:12:00 0.00312764 0.00312158 0.00312461 0.00312461 0.00312461 0.00000606 0.000000 B
39400 2018-10-04 02:27:00 0.00277023 0.00276417 0.00276818 0.00276720 0.00276720 0.00000606 0.000000 B
我要做的是使用以下命令创建数据框:
df_spread = pd.DataFrame(columns=['spread'])
具有100个点差的列:
spread
0 0
1 4.0E-7
2 0.00000120
3 0.00000172
4 0.00000222
5 0.00000250
6 0.00000280
7 0.00000305
8 0.00000323
9 0.00000339
10 0.00000350
我想在新数据框上使用与上一个数据框相同的容器和标签,所以我这样做:
s1 = (df_spread['spread'] * 10**15).astype(np.int64)
df_spread['spread_bin'] = pd.cut(s1, bins=bin_bounds, right=False, labels=sbins.cat.categories)
但这给了我以下错误:'Categorical' object has no attribute 'cat'
知道为什么吗?谢谢!