Nov-18-2019, 07:39 AM
(Nov-15-2019, 11:48 AM)perfringo Wrote: I don't know whether it addresses your problem:
import pandas as pd data = ['2019-05-02 00:03:00', '2019-05-02 00:08:00', '2019-05-02 00:13:00', '2019-05-02 00:18:00', '2019-05-02 00:23:00', '2019-05-02 00:28:00', '2019-05-02 00:33:00'] df = pd.DataFrame({'num': range(len(data))}, index=pd.to_datetime(data))It will create following DataFrame with DatetimeIndex:
Now we can set num value based on time:
Output:num 2019-05-02 00:03:00 0 2019-05-02 00:08:00 1 2019-05-02 00:13:00 2 2019-05-02 00:18:00 3 2019-05-02 00:23:00 4 2019-05-02 00:28:00 5 2019-05-02 00:33:00 6
df.iloc[df.index.indexer_between_time('00:13:00', '23:59:00')] = 20Which will give:
Output:num 2019-05-02 00:03:00 0 2019-05-02 00:08:00 1 2019-05-02 00:13:00 20 2019-05-02 00:18:00 20 2019-05-02 00:23:00 20 2019-05-02 00:28:00 20 2019-05-02 00:33:00 20
Thks for your time but its not really what I want to do