我知道有一些题目类似的问题,但没有一个能真正回答我的问题。 我有一个数据框如下。“index”列实际上是timestamp。A列是多少吨的材料已经倾倒到一个破碎机。B列是每个时间戳的压碎率。我想知道的是,根据破碎率(B列),一堆材料(a列)何时被破碎。你知道吗
有三种可能的情况。你知道吗
我尝试计算A列和B列的累积值,并使用merge\u asof执行模糊联接。但由于没有储存过多的破碎能力,它并没有像预期的那样工作。只应考虑材料加载后的破碎率。你知道吗
A = {'index':range(1,11),'A':[300,0,0,400,0,0,0,0,150,0]}
B = {'index':range(1,11),'B':[102,103,94,120,145,114,126,117,107,100]}
A = pd.DataFrame(data=A)
B = pd.DataFrame(data=B)
以下是预期结果:
IndexA A IndexB B_accumulate
1 300 4 419
4 400 8 502
9 150 10 207
B\u accumulate是压碎率(B)的运行总和,当物料被压碎时(B\u accumulate>;=a),该值被重置为0
创建DF组合A&B:
创建索引:
将0替换为A列中的ffill():
groupby和add索引列:
这里有一个非常详细的解决方案,我希望它可以推广到您的完整数据。我相信你可以简化它。你知道吗
这就产生了
我简化了结构,用Series代替DataFrame,索引从零开始。 应用cumsum()和searchsorted()。你知道吗
相关问题 更多 >
编程相关推荐