Skip to content

Help replicating Excel PITimeFilterVal in Python. #652

Answered by NPhuthiFQML
NPhuthiFQML asked this question in Q&A
Discussion options

You must be logged in to vote

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 % …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by NPhuthiFQML
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant