數據幀我有:如何使用,以獲得特定日期時間指數之後最接近的單行的Python熊貓
A B C
2012-01-01 1 2 3
2012-01-05 4 5 6
2012-01-10 7 8 9
2012-01-15 10 11 12
我現在使用:
date_after = dt.datetime(2012, 1, 7)
frame.ix[date_after:].ix[0:1]
Out[1]:
A B C
2012-01-10 7 8 9
是否有這樣做的更好辦法?我不喜歡我必須指定.ix [0:1]而不是.ix [0],但是如果我不輸出更改爲TimeSeries而不是DataFrame中的單個行。我發現使用原始DataFrame之上的旋轉的TimeSeries重新加工很困難。
沒有.ix[0:1]
:
frame.ix[date_after:].ix[0]
Out[1]:
A 7
B 8
C 9
Name: 2012-01-10 00:00:00
感謝,
約翰
對此的任何文檔? – Pablojim 2013-10-14 09:49:26
@Pablojim:http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Index.searchsorted.html?highlight=searchsorted#pandas.Index.searchsorted – naught101 2018-02-16 03:33:04