获得最后一行,可以使用pandas groupby满足条件
类似
的 | 框 | 数据 | 一个 | 有 | 我 |
---|---|---|---|---|---|
| | | | | |
:18 | 1/1/2200 00:00:00 | 452953 | 9122,57 | 5366,46 | 69.99%1/1/ |
1/1 00:00:00 | 11/3/2022 15:31:18 452954 | 1 | /1 | / | 1/1/ |
11/3/2022 15:31:18 | 1/1/2200 00:00:00 | 452954 | 9122,57 | 5366,46 | 69.99% |
1/ 1/1 | /1/1/1/1900 00:00:00:00 21/7/2021 16:30:46 | 452961 452961 | 6170,98 | 4024,71 | 53.33% |
7/2021 16:30:46 | 11/3/2022 15:31:09 | 452961 | 5312 | 6170,98 | 21 / |
13.98 | 13.98 00:00:00 | 452961 | 9122,57 | 5312 | 71.74%1/1 |
/1/1/1/1/1/ 100:00 | 13/10/2021 14:39:55 | 801286 | 4052,1 1332,1 | 1332,8 | 204.03%13403%13/ |
10/2021/2021 14:39: 55 | 13/10/2021 14:43:09 | 801286 | 4,4732 | 4052,1 | 99.89% |
13/10/2021 14:43:09 | 3/2/2/2/2022 17:16:23 | 801286 | 4473,2 4473,2 | 4,4732 | 99900.00% |
3 /2/2022 17:16:23 | 1/1/2200 00:00:00 | 801286 | 4946,8 | 4473,2 | 10.59% |
我需要检查每个项目_ID,并获取COST_VAR IS的最后一行。如果是最后一行,那没关系,但是如果有一个,则是< 60%,我必须丢弃最后一行60%。输出应该看起来像这样:
date_from | date_to | item_id | value_new | value_old | cost_var |
---|---|---|---|---|---|
11/3/2022 15:31:18 | 1/1/1/1/2200 00:00:00 | 452953 | 9122,57 5366,57 | 5366,46 | 69.99%69.99%11/3/2022 |
15:31:3/2022 15:31: 18 | 1/1/2200 00:00:00 | 452954 | 9122,57 | 5366,46 | 69.99% |
11/3/2022 15:31:09 | 1/1/1/1/2200 00:00:00 | 452961 | 9122,57 | 5312 | 71.74% |
5312 71.74% 802186 802186没有价值,因为最后一行> 60%(99900.00%)的下一行和cost_var< 60%(10.59%)...是否可以这样做?我找不到解决方法。
I have a DataFrame like this:
date_from | date_to | item_id | VALUE_NEW | VALUE_OLD | cost_var |
---|---|---|---|---|---|
1/1/1900 00:00:00 | 11/3/2022 15:31:18 | 452953 | 5366,46 | 4024,71 | 33.34% |
11/3/2022 15:31:18 | 1/1/2200 00:00:00 | 452953 | 9122,57 | 5366,46 | 69.99% |
1/1/1900 00:00:00 | 11/3/2022 15:31:18 | 452954 | 5366,46 | 4024,71 | 33.34% |
11/3/2022 15:31:18 | 1/1/2200 00:00:00 | 452954 | 9122,57 | 5366,46 | 69.99% |
1/1/1900 00:00:00 | 21/7/2021 16:30:46 | 452961 | 6170,98 | 4024,71 | 53.33% |
21/7/2021 16:30:46 | 11/3/2022 15:31:09 | 452961 | 5312 | 6170,98 | 13.92% |
11/3/2022 15:31:09 | 1/1/2200 00:00:00 | 452961 | 9122,57 | 5312 | 71.74% |
1/1/1900 00:00:00 | 13/10/2021 14:39:55 | 801286 | 4052,1 | 1332,8 | 204.03% |
13/10/2021 14:39:55 | 13/10/2021 14:43:09 | 801286 | 4,4732 | 4052,1 | 99.89% |
13/10/2021 14:43:09 | 3/2/2022 17:16:23 | 801286 | 4473,2 | 4,4732 | 99900.00% |
3/2/2022 17:16:23 | 1/1/2200 00:00:00 | 801286 | 4946,8 | 4473,2 | 10.59% |
I need to check each item_id, and get the last row where cost_var is >60%. If it's the last row, that's ok, but if there is a next one, and it is <60%, I have to drop the last row>60%. Output should look like this:
date_from | date_to | item_id | VALUE_NEW | VALUE_OLD | cost_var |
---|---|---|---|---|---|
11/3/2022 15:31:18 | 1/1/2200 00:00:00 | 452953 | 9122,57 | 5366,46 | 69.99% |
11/3/2022 15:31:18 | 1/1/2200 00:00:00 | 452954 | 9122,57 | 5366,46 | 69.99% |
11/3/2022 15:31:09 | 1/1/2200 00:00:00 | 452961 | 9122,57 | 5312 | 71.74% |
Item 802186 returned no value, because last row>60% (99900.00%) has a next row and cost_var<60% (10.59%)... Is it possible to do? I couldn't find a way to solve it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们可以使用
groupby
选择每个item_id
的最后一行,并且只选择其中cost_var&gt; 60%
使用查询
。We can select the last row of each
item_id
usinggroupby
and only select ones wherecost_var > 60%
usingquery
.