Reputation: 525
I have a pandas data frame which I created after reading a csv file.
df = pd.DataFrame(ITC)
print(df.tail(5))
This prints
date open ... low close
488 22-May-2020 188.00 ... 184.60 186.35
489 26-May-2020 190.00 ... 187.80 191.70
490 27-May-2020 192.50 ... 186.90 192.15
491 28-May-2020 192.30 ... 189.00 190.65
492 29-May-2020 190.45 ... 189.00 197.35
I wanted to find max from the 'close' column and df.tail(5).close.max()
works fine.
At last I wanted to print the index of the max value which is 492 so I tried the following
print(df.tail(5).close.idxmax())
but it gives me the following error
TypeError: reduction operation 'argmax' not allowed for this dtype
Any idea on how to go about this ?
Upvotes: 1
Views: 2798
Reputation: 863541
I think close
column is not numeric, but filled by strings repr od numbers.
So use:
df.close = df.close.astype(float)
Or:
df.close = pd.to_numeric(df.close, errors='coerce')
Upvotes: 3