我有一点麻烦,binbing一个熊猫数据帧,然后提取必要的绘图变量。在
我有一个pandas数据帧,如下所示:
a ad td price result profit_loss
12935 10809 -1181 2363 262 1.0 616743.0
13025 -18771 696 1390 350 1.0 1390.0
13079 -20154 348 695 305 0.0 695.0
13085 2370 3945 3150 264 0.0 -828450.0
我想将数据帧的行放入“td”字段的等大小的存储箱中(例如td=0-100、100-200、200-300),并计算属于该td-bin的所有损益条目的总和
例如,对于0-2000年的td bin,盈亏为1390+695。在
然后,我想画出td bin中心与盈亏总额。在
我试过:
^{pr2}$但我不知道如何提取td bin中心和创建的盈亏总额并绘制它们。在
谢谢!在
将bin列添加到dataframe,然后groupby
一个bin应该是
td - td%binsize
(+ binsize/2
,如果你想要中心)。在然后只要groupby越过bin就可以绘制出
如果要在X轴上显示所有空箱子-可以这样做:
说明:
一个助手DF,包含所有垃圾箱
^{pr2}$分组原始数据框
合并/结果数据框
相关问题 更多 >
编程相关推荐