我正在嘗試使用quantopian。這讓我很沮喪。在熊貓中,如何從時間戳索引獲取行?
我有這樣的:
import pandas as pd
import numpy as np
spy_minute_opens = get_pricing(
'SPY', fields='open_price',
start_date='2005-01-01', end_date = '2017-04-01',
frequency='minute')
spy_minute_opens.index.tz = 'US/Eastern'
spy_minute_opens = spy_minute_opens.to_frame()
spy_5min = spy_minute_opens.groupby(pd.TimeGrouper('5T')).agg(['first'])
spy_5min.columns = ['SPY']
這將產生以下:
spy_5min.head(5)
SPY
2005-01-03 09:30:00-05:00 95.507
2005-01-03 09:35:00-05:00 95.531
2005-01-03 09:40:00-05:00 95.625
2005-01-03 09:45:00-05:00 95.547
2005-01-03 09:50:00-05:00 95.586
我想獲得的最小值的行。我得到一個keyError。
spy_5min.idxmin()
SPY 2009-03-06 15:10:00-05:00
dtype: datetime64[ns, US/Eastern]
spy_5min[spy_5min.idxmin()]
KeyError: "['2009-03-06T20:10:00.000000000'] not in index"
任何幫助嗎?!?!
嘗試使用'的.loc []'索引:'spy_5min.loc [spy_5min.idxmin()]' – MaxU