pm4py.objects.log.util.dataframe_utils module#
- class pm4py.objects.log.util.dataframe_utils.Parameters(*values)[source]#
Bases:
Enum- PARTITION_COLUMN = 'partition_column'#
- CASE_ID_KEY = 'pm4py:param:case_id_key'#
- CASE_PREFIX = 'case:'#
- CASE_ATTRIBUTES = 'case_attributes'#
- MANDATORY_ATTRIBUTES = 'mandatory_attributes'#
- MAX_NO_CASES = 'max_no_cases'#
- MIN_DIFFERENT_OCC_STR_ATTR = 5#
- MAX_DIFFERENT_OCC_STR_ATTR = 50#
- TIMESTAMP_KEY = 'pm4py:param:timestamp_key'#
- ACTIVITY_KEY = 'pm4py:param:activity_key'#
- PARAM_ARTIFICIAL_START_ACTIVITY = 'pm4py:param:art_start_act'#
- PARAM_ARTIFICIAL_END_ACTIVITY = 'pm4py:param:art_end_act'#
- INDEX_KEY = 'index_key'#
- CASE_INDEX_KEY = 'case_index_key'#
- USE_EXTREMES_TIMESTAMP = 'use_extremes_timestamp'#
- ADD_CASE_IDENTIFIER_COLUMN = 'add_case_identifier_column'#
- DETERMINISTIC = 'deterministic'#
- pm4py.objects.log.util.dataframe_utils.insert_partitioning(df, num_partitions, parameters=None)[source]#
Insert the partitioning in the specified dataframe
- Parameters:
df – Dataframe
num_partitions – Number of partitions
parameters – Parameters of the algorithm
- Returns:
Partitioned dataframe
- Return type:
df
- pm4py.objects.log.util.dataframe_utils.legacy_parquet_support(df, parameters=None)[source]#
For legacy support, Parquet files columns could not contain a “:” that has been arbitrarily replaced by a replacer string. This string substitutes the replacer to the :
- Parameters:
dataframe – Dataframe
parameters – Parameters of the algorithm
- pm4py.objects.log.util.dataframe_utils.table_to_stream(table, parameters=None)[source]#
Converts a Pyarrow table to an event stream
- Parameters:
table – Pyarrow table
parameters – Possible parameters of the algorithm
- pm4py.objects.log.util.dataframe_utils.table_to_log(table, parameters=None)[source]#
Converts a Pyarrow table to an event log
- Parameters:
table – Pyarrow table
parameters – Possible parameters of the algorithm
- pm4py.objects.log.util.dataframe_utils.convert_timestamp_columns_in_df(df, timest_format=None, timest_columns=None)[source]#
Convert all dataframe columns in a dataframe
- Parameters:
df – Dataframe
timest_format – (If provided) Format of the timestamp columns in the CSV file
timest_columns – Columns of the CSV that shall be converted into timestamp
- Returns:
Dataframe with timestamp columns converted
- Return type:
df
- pm4py.objects.log.util.dataframe_utils.sample_dataframe(df, parameters=None)[source]#
Sample a dataframe on a given number of cases
- Parameters:
df – Dataframe
parameters – Parameters of the algorithm, including: - Parameters.CASE_ID_KEY - Parameters.CASE_ID_TO_RETAIN
- Returns:
Sampled dataframe
- Return type:
sampled_df
- pm4py.objects.log.util.dataframe_utils.automatic_feature_selection_df(df, parameters=None)[source]#
Performs an automatic feature selection on dataframes, keeping the features useful for ML purposes
- Parameters:
df – Dataframe
parameters – Parameters of the algorithm
- Returns:
Dataframe with only the features that have been selected
- Return type:
featured_df
- pm4py.objects.log.util.dataframe_utils.select_number_column(df: DataFrame, fea_df: DataFrame, col: str, case_id_key='case:concept:name') DataFrame[source]#
Extract a column for the features dataframe for the given numeric attribute
- Parameters:
df – Dataframe
fea_df – Feature dataframe
col – Numeric column
case_id_key – Case ID key
- Returns:
Feature dataframe (desidered output)
- Return type:
fea_df
- pm4py.objects.log.util.dataframe_utils.select_string_column(df: DataFrame, fea_df: DataFrame, col: str, case_id_key='case:concept:name') DataFrame[source]#
Extract N columns (for N different attribute values; hotencoding) for the features dataframe for the given string attribute
- Parameters:
df – Dataframe
fea_df – Feature dataframe
col – String column
case_id_key – Case ID key
- Returns:
Feature dataframe (desidered output)
- Return type:
fea_df
- pm4py.objects.log.util.dataframe_utils.get_features_df(df: DataFrame, list_columns: List[str], parameters: Dict[Any, Any] | None = None) DataFrame[source]#
Given a dataframe and a list of columns, performs an automatic feature extraction
- Parameters:
df – Dataframe
list_column – List of column to consider in the feature extraction
parameters – Parameters of the algorithm, including: - Parameters.CASE_ID_KEY: the case ID
- Returns:
Feature dataframe (desidered output)
- Return type:
fea_df
- pm4py.objects.log.util.dataframe_utils.automatic_feature_extraction_df(df: DataFrame, parameters: Dict[Any, Any] | None = None) DataFrame[source]#
Performs an automatic feature extraction given a dataframe
- Parameters:
df – Dataframe
parameters – Parameters of the algorithm, including: - Parameters.CASE_ID_KEY: the case ID - Parameters.MIN_DIFFERENT_OCC_STR_ATTR - Parameters.MAX_DIFFERENT_OCC_STR_ATTR
- Returns:
Dataframe with the features
- Return type:
fea_df
- pm4py.objects.log.util.dataframe_utils.insert_artificial_start_end(df0: DataFrame, parameters: Dict[Any, Any] | None = None) DataFrame[source]#
Inserts the artificial start/end activities in a Pandas dataframe
- Parameters:
df0 – Dataframe
parameters – Parameters of the algorithm, including: - Parameters.CASE_ID_KEY: the case identifier - Parameters.TIMESTAMP_KEY: the timestamp - Parameters.ACTIVITY_KEY: the activity
- Returns:
Dataframe with artificial start/end activities
- Return type:
enriched_df
- pm4py.objects.log.util.dataframe_utils.dataframe_to_activity_case_table(df: DataFrame, parameters: Dict[Any, Any] | None = None)[source]#
Transforms a Pandas dataframe into: - an “activity” table, containing the events and their attributes - a “case” table, containing the cases and their attributes
- Parameters:
df – Dataframe
parameters – Parameters of the algorithm that should be used, including: - Parameters.CASE_ID_KEY => the column to be used as case ID (shall be included both in the activity table and the case table) - Parameters.CASE_PREFIX => if a list of attributes at the case level is not provided, then all the ones of the dataframe
starting with one of these are considered.
Parameters.CASE_ATTRIBUTES => the attributes of the dataframe to be used as case columns
- Returns:
activity_table – Activity table
case_table – Case table