Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14418

Extract instances from perminute timeseries data where the POWER value is 0 continuously for greater than 0 minutes

$
0
0

I have huge time series dataset containing TIME, POWER as columns, I'm taking this dataset in window of 30 minutes and inside each window if POWER value is 0 for greater than 10 minutes continuously, then I'll store the start_time, end_time, duration, and number of occurrences of such instance within the window in the dictionary.

    window_size = 30    # Identify anomalous instances within the window    anomalous_ranges = []    for i in range(0, len(df) - 1, window_size):            batch = df.iloc[i:i+window_size]            # print(batch)            start_time = None            end_time = None            for idx, row in batch.iterrows():                p = row['ACTIVEPOWER']                if p == 0:                    if start_time is None:                        start_time = row['TIME']                    else:                        end_time = row['TIME']                else:                        if start_time and end_time is not None:                        duration = (pd.to_datetime(end_time) - pd.to_datetime(start_time)).total_seconds() / 60.0                        print(duration)                        label = 'Zero Values'                        if duration >= 10:                            anomalous_ranges.append((start_time, end_time, duration,label))                        start_time = None

Output:anomalous_ranges

Start Time  End Time    Duration (Minutes)  Remarks0   2023-04-19 01:37:30 2023-04-19 01:53:30 16.0    Zero Values1   2023-04-19 14:37:30 2023-04-19 14:50:30 13.0    Zero Values2   2023-04-19 15:37:30 2023-04-19 16:03:30 26.0    Zero Values3   2023-04-20 05:16:30 2023-04-20 05:26:30 10.0    Zero Values4   2023-04-21 14:37:30 2023-04-21 14:49:30 12.0    Zero Values5   2023-04-22 23:07:30 2023-04-22 23:25:30 18.0    Zero Values6   2023-04-24 20:07:30 2023-04-24 20:26:30 19.0    Zero Values7   2023-04-25 11:07:30 2023-04-25 11:18:30 11.0    Zero Values...

in the dataset, there are more instances which are not getting captured here.imageif you see only red block instances getting captured but after the first red block, in the next window the power is 0 continuously for greater than 10 minute


Viewing all articles
Browse latest Browse all 14418

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>