0

I have a small dataframe like below:

Dataframe

Here is the code:

my_dates = [datetime(2016, 1, 1), datetime(2016, 1, 2), datetime(2016,1,3)]
dt_ind = pd.DatetimeIndex(my_dates)
data = [2,8,15]
cols = ['num']
df = pd.DataFrame(data,dt_ind,cols)

I am trying to find the date on which we have high value. So I used:

df['num'].argmax()

But instead of showing output as 2016-01-03, I am getting 2. What am I doing wrong?

martineau
  • 119,623
  • 25
  • 170
  • 301
Jinni
  • 1
  • 1

2 Answers2

1

argmax returns index of the highest value, so in your case it's 2. Try max()

Krolik1337
  • 21
  • 6
  • I actually want index but not as number but as an time stamp. Which in this case is 2016-01-03 – Jinni Aug 25 '20 at 16:49
0

use

df['num'].idxmax()

instead of

df['num'].argmax()

Parimal
  • 1
  • 1