<jupyter_start><jupyter_text>--- 🟩 Transition ProbabilitiesWe would like to analyze how customers switch between sections of the supermarket. Calculate and visualize the probability of transitions from section A to B by counting all observed transitions.---<jupyter_code>df_mon_cust_6 = df_mon[df_mon["customer_no"].isin([6])].copy()
df_mon_cust_6['location_before'] = df_mon_cust_6['location'].shift(1).fillna('entrance')
df_mon_cust_6['timnestamp_before'] = df_mon_cust_6['timestamp'].shift(1)
df_mon_cust_6['timnestamp_diff'] = df_mon_cust_6['timestamp'] - df_mon_cust_6['timnestamp_before']
df_mon_cust_6
pd.crosstab(df_mon_cust_6['location'], df_mon_cust_6['location_before'], normalize=0)
def transition_probas(df=df_mon):
    """
    Given a dataframe
    prints the proba matrices 
    for every customer
    """

    customer_no = 1
    for i in range(df["customer_no"].max()):
        df_temp = df[df["customer_no"].isin([customer_no])].copy()
        df_temp['location_before'] = df_temp['location'].shift(1)
        df_temp['timnestamp_before'] = df_temp['timestamp'].shift(1)
        df_temp['timnestamp_diff'] = df_temp['timestamp'] - df_temp['timnestamp_before']
        print('Customer number: ' + str(customer_no))
        print()
        print(pd.crosstab(df_temp['location'], df_temp['location_before'], normalize=1))
        print()
        print("---")
        print()
        customer_no += 1

transition_probas(df_mon)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14004078857919783, 'fraction_numerical': 0.013596193065941536, 'mean_word_length': 5.0081632653061225, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '399450', 'license': 'MIT', 'n_tokens_mistral': 513, 'n_tokens_neox': 494, 'n_words': 85, 'path': 'transition_probas/Transition_Probas_Pavel.ipynb', 'repo_name': 'ai-aksoyoglu/supermarket-simulation_Markov-chain', 'size': '1471'}