pm4py.filtering.filter_prefixes#

pm4py.filtering.filter_prefixes(log: EventLog | DataFrame, activity: str, strict: bool = True, first_or_last: str = 'first', activity_key: str = 'concept:name', timestamp_key: str = 'time:timestamp', case_id_key: str = 'case:concept:name') EventLog | DataFrame[source]#

Filters the log, keeping the prefixes leading up to a given activity. For example, for a log with traces: - A,B,C,D - A,B,Z,A,B,C,D - A,B,C,D,C,E,C,F

The prefixes to “C” are respectively: - A,B - A,B,Z,A,B - A,B

Parameters:
  • log – Event log or Pandas DataFrame.

  • activity (str) – Target activity for the filter.

  • strict (bool) – Applies the filter strictly, cutting the occurrences of the selected activity.

  • first_or_last (str) – Decides if the first or last occurrence of an activity should be selected as the baseline for the filter.

  • activity_key (str) – Attribute to be used for the activity.

  • timestamp_key (str) – Attribute to be used for the timestamp.

  • case_id_key (str) – Attribute to be used as case identifier.

Returns:

Filtered event log or Pandas DataFrame.

import pm4py

filtered_dataframe = pm4py.filter_prefixes(
    dataframe,
    'Act. C',
    activity_key='concept:name',
    timestamp_key='time:timestamp',
    case_id_key='case:concept:name'
)