从 pandas 数据框中获取最小和最大日期 [英] Getting min and max Dates from a pandas dataframe
本文介绍了从 pandas 数据框中获取最小和最大日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从数据框的主轴获取最小和最大日期?
How do I get the min and max Dates from a dataframe's 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
本质上讲,我想要一种获取最小和最大的方法日期,即 2014-03-13
和 2014-03-31
。我尝试使用 numpy.min
或 df.min(axis = 0)
,我可以获取最小值或最大值,但这不是我想要的
Essentially I want a way to get the min and max dates, i.e. 2014-03-13
and 2014-03-31
. I tried using numpy.min
or df.min(axis=0)
, I'm able to get the min or max value but that's not what I want
推荐答案
日期是您的索引,因此您想这样做,
'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
这篇关于从 pandas 数据框中获取最小和最大日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文