Python 从熊猫数据框中获取最小和最大日期

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23178129/
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-08-19 02:25:28  来源:igfitidea点击:

Getting min and max Date's from a pandas dataframe

pythondatetimepandas

提问by pyCthon

How do I get the min and max Date's from a dataframes major axis?

如何从数据帧主轴获取最小和最大日期?

           value
Date                                           
2014-03-13  10000.000 
2014-03-21   2000.000 
2014-03-27   2000.000 
2014-03-17    200.000 
2014-03-17      5.000 
2014-03-17     70.000 
2014-03-21    200.000 
2014-03-27      5.000 
2014-03-27     25.000 
2014-03-31      0.020 
2014-03-31     12.000 
2014-03-31      0.022

Essentially I want a way to get the min and max dates,i.e. 2014-03-13and 2014-03-31. I tried using numpy.minor df.min(axis=0), I'm able to get the min or max value but thats not what I want

基本上我想要一种方法来获取最小和最大日期,即2014-03-132014-03-31. 我尝试使用numpy.minor df.min(axis=0),我能够获得最小值或最大值,但这不是我想要的

采纳答案by Karl D.

'Date' is your index so you want to do,

“日期”是你的索引,所以你想做,

print (df.index.min())
print (df.index.max())

2014-03-13 00:00:00
2014-03-31 00:00:00

回答by J.Weed

min(df['some_property'])
max(df['some_property'])

The build-in function works fine with dataframe

内置函数适用于数据框