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

如何从数据帧的主轴得到最小和最大日期?

           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-132014-03-31。我尝试使用 numpy.mindf.min(axis=0),我能够得到的最小值或最大值,但这不是我想要的

183819 次浏览

'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
min(df['some_property'])
max(df['some_property'])

The built-in functions work well with Pandas Dataframes.

Use agg to determine the minimum and maximum value in one line:

In [5]: df['Date'].agg(['min', 'max'])
Out[5]:
min    2014-03-13
max    2014-03-31

If your desired column is in the index, you have to reset the index first:

df.reset_index()['Date'].agg(['min', 'max'])