1
我正在尋找使用日期時間索引在熊貓數據框中的6小時的差距,我想創建一個列表與日期時間對象剛剛在使用列表理解這樣的差距之後:熊貓日期時間索引列表理解
starttimes = [x for i, x in enumerate(data.index) if ((x - x[i-1]).seconds/3600.0) > 6 ]
,但我得到以下類型的錯誤:
TypeError: 'Timestamp' object does not support indexing
的枚舉(data.index)之後出現的錯誤,但我不知道爲什麼我收到這個錯誤,因爲我可以做的:
(data.index[0] - data.index[1]).seconds/3600.0 > 6
蠻好的,輸出是真的。
我也試過這種方式,獲得了不同類型的錯誤:
starttime = [x for i, x in enumerate(WaterTest) if ((x.index - x.index[i-1]).seconds/3600.0) > 6 ]
TypeError: 'builtin_function_or_method' object has no attribute '__getitem__'
有沒有一種方法可以輕鬆地做到這一點?我必須在我的代碼中經常使用這些語句,並且能夠以類似於此的方式編寫它們會很好。
我numpy的版本是1.7.1,但因爲你沒有以上我需要抓住一個較新的版本,我不能使用爲.diff()或。適用於TD? – pbreach
你能顯示你的代碼嗎? – Jeff
忘記導入日期時間,但它現在工作,速度很快!謝謝 – pbreach