我有以下 df prices:
open high low close
timestamp
2021-06-08 07:30:00 00:00 126.1000 126.1600 125.9600 126.0600
2021-06-08 08:15:00 00:00 126.0500 126.3000 126.0500 126.3000
2021-06-08 09:00:00 00:00 126.2700 126.3200 126.2200 126.2800
現在我想分配列中值high最高的行的時間戳。
我可以設法在high列中找到最高價格,但不知道如何“獲取”其時間戳?
high_prices = prices['high']
highest_price = high_prices.max()
timestamp_highest_price = ?
uj5u.com熱心網友回復:
由于您的時間戳是索引,因此請使用idxmax,這將直接為您提供時間戳:
idx_max = df['high'].idxmax()
輸出: '2021-06-08 09:00:00 00:00'
然后根據需要切片最高價格:
df.loc[idx_max, 'high']
輸出: 126.32
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/400814.html
下一篇:如何從csv檔案中洗掉NaN值?
