Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting min and max Dates from a pandas dataframe

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 

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

like image 672
pyCthon Avatar asked Apr 20 '14 03:04

pyCthon


People also ask

How do you find the max and min of a column in pandas?

Pandas dataframe. max() method finds the maximum of the values in the object and returns it. If the input is a series, the method will return a scalar which will be the maximum of the values in the series.

How do you get min in pandas?

Pandas DataFrame min() MethodThe min() method returns a Series with the minimum value of each column. By specifying the column axis ( axis='columns' ), the max() method searches column-wise and returns the minimum value for each row.


1 Answers

'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 
like image 195
Karl D. Avatar answered Oct 06 '22 22:10

Karl D.