简体   繁体   English

如何过滤掉最后一个排名?

[英]How do I filter out for last rank only?

I have a dataset where for each unique OrderID , the status for a product changes overtime and the time for each of these changes is recorded. 我有一个数据集,对于每个唯一的OrderID ,产品的状态随时间变化,并记录每个变化的时间。

I have grouped all the records by OrderID and ranked them. 我按OrderID对所有记录进行了分组并对它们进行了排名。 I now only want records that were the last rank for each OrderID . 我现在只想要每个OrderID的最后一个等级的记录。

Grouped = sortedOrdersAll.sort_values(['ordid','DateTime'],ascending=True).groupby(['ordid','DateTime']) 

Grouped.first()

排名和分组

没有使用groupby,我认为你可以做到这一点

df.sort_values('DateTime').drop_duplicates(subset=['ordid'], keep='last')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何对在给定数据中挑选出的功能列表进行排名,并对功能进行排名? - How do I rank a list of features that I have picked out in the given data and rank the features? 如何仅对数据框中的特定行进行排名? - How do I rank only specific rows within a dataframe? 如何从该数据框中过滤单词? - How do I filter the words out of this dataframe? 如何仅从此列表中过滤带有哈希标记的单词,然后输出到文本文件? - How do I filter out only the hash tagged word from this list and output to a text file? 如何仅筛选出位于偶数位置的列表中的项目? - How do I filter out only items from a list which is in an even position? 如何过滤 json 打印以仅吐出某些值 - How do I filter a json print to only spit out certain values 如何仅打印最后一个 output? - How do I print the last output only? 如何过滤嵌套的案例以过滤出python - How do I filter nested cases to be filter out python 我如何解决此错误“形状必须为4级但为3级” - how do I solve this error “Shape must be rank 4 but is rank 3” 我如何让我的字典从我的正则表达式循环中打印出更多的值,而不是只打印最后一个值? - How do I get my dictionary to print out more values from my regex loop instead of printing only the last one?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM