【发布时间】:2018-12-29 23:47:12
【问题描述】:
我想按特定范围(0,1;0,2;等)对我的值 (CPA%) 进行分组。 现在我的代码看起来像:
conn = psycopg2.connect("dbname=monty user=postgres host=localhost password=postgres")
cur = conn.cursor()
cur.execute("SELECT * FROM binance.zrxeth_ob_indicators;")
row = cur.fetchall()
df = pd.DataFrame(row,columns=['timestamp', 'topAsk', 'topBid', 'CPA', 'midprice', 'CPB', 'spread', 'CPA%', 'CPB%'])
pd.cut(df,0.001)
我的输出如下:
CPA%
0.005822
0.007129
0.008345
0.022531
0.016073
0.013433
0.013616
0.016571
如何按特定范围按这些值分组并计算它们?我对库 pandas 不太熟悉,并且不正确理解如何使用它...
【问题讨论】:
-
您能否以可以复制到文本编辑器中的方式添加 CPA 列?