」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > 如何根據時間戳範圍加入數據范圍?

如何根據時間戳範圍加入數據范圍?

發佈於2025-03-22
瀏覽:591

[

How to Join DataFrames Based on Timestamp Ranges?
基於列值ranges

實現這一目標的一種方法是從df_2中的開始和末端列創建一個間隔索引。然後,我們可以使用get_loc方法獲得DF_1中每個時間戳的相應事件。這是此解決方案的python代碼:

#從df_2創建間隔索引 df_2.index = pd.intervalindex.from_arrays(df_2 ['start'],df_2 ['end'],nluct ='ot ='兩者') #獲取DF_1中每個時間戳的相應事件 df_1 ['event'] = df_1 ['timestamp']。應用(lambda x:df_2.iloc [df_2.index.get_loc(x)] ['event''])在DF_1中命名為DF_1中的新列,其中包含每個符號事件的df_1,該事件為每個fimestamp shiles of Seppefs seppecied sefters necters necters necters nects nects necters necters nectife nectife the nectement。生成的加入數據框將包含以下列: TIMESTAMP A B事件

最新教學 更多>

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3