pm4py.util.pandas_utils module#

pm4py.util.pandas_utils.get_default_dataframe_environment()[source]#
pm4py.util.pandas_utils.to_dict_records(df)[source]#

Pandas dataframe to dictionary (records method)

Parameters:

df – Dataframe

Returns:

List containing a dictionary for each row

Return type:

list_dictio

pm4py.util.pandas_utils.to_dict_index(df)[source]#

Pandas dataframe to dictionary (index method)

Parameters:

df – Dataframe

Returns:

dict like {index -> {column -> value}}

Return type:

dict

pm4py.util.pandas_utils.insert_index(df, column_name='@@index', copy_dataframe=True, reset_index=True)[source]#

Inserts the dataframe index in the specified column

Parameters:
  • df – Dataframe

  • column_name – Name of the column that should host the index

  • copy_dataframe – Establishes if the original dataframe should be copied before inserting the column

Returns:

Dataframe with index

Return type:

df

pm4py.util.pandas_utils.insert_case_index(df, column_name='@@case_index', case_id='case:concept:name', copy_dataframe=True)[source]#

Inserts the case number in the dataframe

Parameters:
  • df – Dataframe

  • column_name – Name of the column that should host the case index

  • case_id – Case identifier

  • copy_dataframe – Establishes if the original dataframe should be copied before inserting the column

Returns:

Dataframe with case index

Return type:

df

pm4py.util.pandas_utils.insert_ev_in_tr_index(df: DataFrame, case_id: str = 'case:concept:name', column_name: str = '@@index_in_trace', copy_dataframe=True) DataFrame[source]#

Inserts a column that specify the index of the event inside the case

Parameters:
  • df – Dataframe

  • case_id – Column that hosts the case identifier

  • column_name – Name of the column that should host the index

Returns:

Dataframe with index

Return type:

df

pm4py.util.pandas_utils.format_unique(values)[source]#
pm4py.util.pandas_utils.insert_feature_activity_position_in_trace(df: DataFrame, case_id: str = 'case:concept:name', activity_key: str = 'concept:name', prefix='@@position_')[source]#

Inserts additional columns @@position_ACT1, @@position_ACT2 … which are populated for every event having activity ACT1, ACT2 respectively, with the index of the event inside its case.

Parameters:
  • df – Pandas dataframe

  • case_id – Case idntifier

  • activity_key – Activity

  • prefix – Prefix of the “activity position in trace” feature (default: @@position_)

Returns:

Pandas dataframe

Return type:

df

pm4py.util.pandas_utils.insert_case_arrival_finish_rate(log: DataFrame, case_id_column='case:concept:name', timestamp_column='time:timestamp', start_timestamp_column=None, arrival_rate_column='@@arrival_rate', finish_rate_column='@@finish_rate') DataFrame[source]#

Inserts the arrival/finish rate in the dataframe.

Parameters:

log – Pandas dataframe

Returns:

Pandas dataframe enriched by arrival and finish rate

Return type:

log

pm4py.util.pandas_utils.insert_case_service_waiting_time(log: DataFrame, case_id_column='case:concept:name', timestamp_column='time:timestamp', start_timestamp_column=None, diff_start_end_column='@@diff_start_end', service_time_column='@@service_time', sojourn_time_column='@@sojourn_time', waiting_time_column='@@waiting_time') DataFrame[source]#

Inserts the service/waiting/sojourn time in the dataframe.

Parameters:
  • log – Pandas dataframe

  • parameters – Parameters of the method

Returns:

Pandas dataframe with service, waiting and sojourn time

Return type:

log

pm4py.util.pandas_utils.check_is_pandas_dataframe(log)[source]#

Checks if a log object is a dataframe

Parameters:

log – Log object

Returns:

Is dataframe?

Return type:

boolean

pm4py.util.pandas_utils.instantiate_dataframe(*args, **kwargs)[source]#
pm4py.util.pandas_utils.instantiate_dataframe_from_dict(*args, **kwargs)[source]#
pm4py.util.pandas_utils.instantiate_dataframe_from_records(*args, **kwargs)[source]#
pm4py.util.pandas_utils.get_grouper(*args, **kwargs)[source]#
pm4py.util.pandas_utils.get_total_seconds(difference)[source]#
pm4py.util.pandas_utils.convert_to_seconds(dt_column)[source]#
pm4py.util.pandas_utils.dataframe_column_string_to_datetime(*args, **kwargs)[source]#
pm4py.util.pandas_utils.read_csv(*args, **kwargs)[source]#
pm4py.util.pandas_utils.concat(*args, **kwargs)[source]#
pm4py.util.pandas_utils.merge(*args, **kwargs)[source]#
pm4py.util.pandas_utils.check_pandas_dataframe_columns(df, activity_key=None, case_id_key=None, timestamp_key=None, start_timestamp_key=None)[source]#

Checks if the dataframe contains all the required columns. If not, raise an exception

Parameters:

df – Pandas dataframe