在 Pandas 中获取最大值的行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42234039/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 02:58:49  来源:igfitidea点击:

Getting the row with max value in Pandas

pythonpandas

提问by Keithx

Have a df like that:

有一个这样的 df:

enter image description here

在此处输入图片说明

I'd like to have a dataframe with only row with max date in it. How can it be performed?

我想要一个数据框,其中只有最大日期的行。如何执行?

Thanks!

谢谢!

回答by Vaishali

Find the most recent date:

查找最近的日期:

recent_date = df['date'].max()

And then get the dataframe with the recent date:

然后获取具有最近日期的数据框:

df[df['date'] == recent_date]