元のデータ
df1
python
1>>> print(df1)
2 時刻
30 2021-12-05 17:30:00
41 2021-12-07 05:55:00
52 2021-12-10 08:32:00
63 2021-12-05 10:14:00
df2
python
1>>> print(df2)
2 開始時刻 終了時刻 データ
30 2021-12-01 10:00:00 2021-12-01 15:00:00 0
41 2021-12-01 15:00:00 2021-12-01 20:00:00 1
52 2021-12-01 20:00:00 2021-12-02 01:00:00 2
63 2021-12-02 01:00:00 2021-12-02 06:00:00 3
74 2021-12-02 06:00:00 2021-12-02 11:00:00 4
85 2021-12-02 11:00:00 2021-12-02 16:00:00 5
96 2021-12-02 16:00:00 2021-12-02 21:00:00 6
107 2021-12-02 21:00:00 2021-12-03 02:00:00 7
118 2021-12-03 02:00:00 2021-12-03 07:00:00 8
129 2021-12-03 07:00:00 2021-12-03 12:00:00 9
1310 2021-12-03 12:00:00 2021-12-03 17:00:00 10
1411 2021-12-03 17:00:00 2021-12-03 22:00:00 11
1512 2021-12-03 22:00:00 2021-12-04 03:00:00 12
1613 2021-12-04 03:00:00 2021-12-04 08:00:00 13
1714 2021-12-04 08:00:00 2021-12-04 13:00:00 14
1815 2021-12-04 13:00:00 2021-12-04 18:00:00 15
1916 2021-12-04 18:00:00 2021-12-04 23:00:00 16
2017 2021-12-04 23:00:00 2021-12-05 04:00:00 17
2118 2021-12-05 04:00:00 2021-12-05 09:00:00 18
2219 2021-12-05 09:00:00 2021-12-05 14:00:00 19
2320 2021-12-05 14:00:00 2021-12-05 19:00:00 20
2421 2021-12-05 19:00:00 2021-12-06 00:00:00 21
2522 2021-12-06 00:00:00 2021-12-06 05:00:00 22
2623 2021-12-06 05:00:00 2021-12-06 10:00:00 23
2724 2021-12-06 10:00:00 2021-12-06 15:00:00 24
2825 2021-12-06 15:00:00 2021-12-06 20:00:00 25
2926 2021-12-06 20:00:00 2021-12-07 01:00:00 26
3027 2021-12-07 01:00:00 2021-12-07 06:00:00 27
3128 2021-12-07 06:00:00 2021-12-07 11:00:00 28
3229 2021-12-07 11:00:00 2021-12-07 16:00:00 29
処理
python
1df_cross = pd.merge(df1,df2,how='cross')
2result = pd.merge(df1, df_cross[(df_cross['開始時刻']<df_cross['時刻']) & (df_cross['時刻']<df_cross['終了時刻'])][['時刻', 'データ']], how='left')
実行結果
python
1>>> print(result)
2 時刻 データ
30 2021-12-05 17:30:00 20.0
41 2021-12-07 05:55:00 27.0
52 2021-12-10 08:32:00 NaN
63 2021-12-05 10:14:00 19.0
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/12/10 02:27