例如, Temp Hum WSDateTime 2019-08-01 00:00:00 35.9615 20.51460 1.2872252019-08-01 00:20:00 36.5795 21.92870 2.2132252019-08-01 00:40:00 36.2885 22.62970 2.3311752019-08-01 01:00:00 36.1095 22.76075 2.532800間隔顯然是20分鐘,但是是否有提取它的功能?我正在編寫一個腳本,使用df.resample(rate).mean()重新采樣到更低的分辨率,我想確保只有當速率大于df的速率時,我們才運行腳本。將較低分辨率的數據轉換為較高分辨率是沒有意義的。在此示例中,“60T”的速率是可以接受的,因為它會將 20 分鐘數據轉換為每小時數據。但是,“10T”的速率應該是不可接受的。
2 回答

人到中年有點甜
TA貢獻1895條經驗 獲得超7個贊
嘗試:
# if index not datetime object, then
# df.index = pd.to_datetime(df.index)
>>> pd.Series(df.index).diff().mean().components.minutes
20
#or,
>>> pd.Series(df.index).diff().iloc[-1].components.minutes
20

烙印99
TA貢獻1829條經驗 獲得超13個贊
這取決于數據,如果指定了頻率,請使用DatetimeIndex.freqstr:
print (df.index.freqstr)
20T
如果未指定,則可以通過將 DatetimeIndex 與 DataFrame.asfreq 進行轉換來比較它:
idx = df.asfreq('20T').index
m = (df.index == idx).all()
print (m)
True
print (idx.freqstr)
20T
添加回答
舉報
0/150
提交
取消