Help replicating Excel PITimeFilterVal in Python. #652
-
Hi. I am in need of replicating the PITimeFilterVal Excel PIDataLink function in Python, with the purpose of calculating the duration over which the value of a PIPoint is above a given limit. So far, I recognise that I can pull the PI series recorded values. I then have the series, but am stumped as how to calculate durations the same way that PITimeFilterVal() function does:
Any help is greatly appreciated. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I have since found a workaround. I generate a dataframe from the PISeries object, then create a "flags" column based on a rolling mean with a window of 1, which will evaluate each item against the filter.: From there another column is created, that allocates a group number to each of the regions in the dataframes where the 'flag' is either true or false: I can then split the dataframe by 'group' column into a list of dataframes As a note, the builtin sum() of python is meant for integer and float iterables, so a solution is to convert the list to a pandas series again, and then use the series' sum function. Credit to the following links: |
Beta Was this translation helpful? Give feedback.
I have since found a workaround. I generate a dataframe from the PISeries object, then create a "flags" column based on a rolling mean with a window of 1, which will evaluate each item against the filter.:
val_df['flags'] = val_df['values'].rolling(1, center=True).mean() >= filter
From there another column is created, that allocates a group number to each of the regions in the dataframes where the 'flag' is either true or false:
val_df["group"] = val_df["flag"].diff().cumsum().bfill().astype(int)
I can then split the dataframe by 'group' column into a list of dataframes
for i in range(val_df["group"].max() + 1): if (val_df["flag"][0] and (i % 2 == 0)) or ((not val_df["flag"][0]) and (i % …