<jupyter_start><jupyter_text>Load raw file<jupyter_code>df = pd.read_csv(FILE)
df.head()<jupyter_output><empty_output><jupyter_text>Get line ups per point and game without duplicates<jupyter_code>line_ups = df.filter(like="Player") \
    .dropna(axis=1) \
    .assign(total_points=df.filter(like="Score").sum(axis=1)) \
    .assign(game=df["Opponent"]) \
    .drop_duplicates()
    
line_ups.head()<jupyter_output><empty_output><jupyter_text>Convert to long format and back to get each player as binary variable<jupyter_code>long_line_ups = pd.melt(line_ups, id_vars=["total_points", "game"], value_name="player") \
    .drop("variable", axis=1) \
    .assign(count=1)
    
long_line_ups.head()
# convert back to wide as binary
binary_line_ups = long_line_ups.pivot_table(columns="player", 
                                            index=["total_points", "game"], 
                                            values="count")

# fill missings with 0 and create 'Anonymous' player which corresponds to a throwaway
binary_line_ups = binary_line_ups.fillna(0) \
    .astype(int) \
    .assign(Anonymous=1)

binary_line_ups.head()<jupyter_output><empty_output><jupyter_text>Get all combinations of player tuples and points played together<jupyter_code># get all combinations of player tuples
players = itertools.combinations(binary_line_ups.columns, 2)

# define helper function to compute points played together
def points_played_together(sub_df, player_tuple):
    player_columns = list(player_tuple)
    played_points_bool = sub_df[player_columns].sum(axis=1)
    return (played_points_bool == 2).sum()

played_together = {player_tuple: points_played_together(binary_line_ups, player_tuple)
                   for player_tuple in players}

played_together_rev = {(player2, player1): count 
                       for (player1, player2), count in played_together.items()}   

played_together.update(played_together_rev)<jupyter_output><empty_output><jupyter_text>Create final data frame with passer, receiver and pass stats<jupyter_code># consider only offense event type
mask = df["Event Type"] == "Offense"
passes = df.loc[mask, PASS_RECEIVER]

# create tupled series to apply value count 
res_df = pd.Series([tuple(x) for x in passes.values]) \
    .value_counts() \
    .to_frame("Passes") \
    .reindex(played_together.keys()) \
    .fillna(0) \
    .assign(PlayedTogether=pd.Series(played_together))
    
# create average passes per point played together
res_df["PassesPerPoint"] = (res_df["Passes"] / res_df["PlayedTogether"]).fillna(0).sort_values()
res_df["Passer"], res_df["Receiver"] = zip(*res_df.index.values.tolist())
res_df = res_df.reset_index(drop=True) \
    .sort_values(PASS_RECEIVER) \
    .replace("Anonymous", "Throwaway")

res_df.head()<jupyter_output><empty_output><jupyter_text>Write csv output formats<jupyter_code>res_df[PASS_RECEIVER + ["Passes"]].to_csv("plots/data/passes_absolute.csv", index=False)
res_df[PASS_RECEIVER + ["PlayedTogether"]].query("Receiver != 'Throwaway' and Passer != 'Throwaway'").to_csv("plots/data/played_together.csv", index=False)
res_df[PASS_RECEIVER + ["PassesPerPoint"]].to_csv("plots/data/passes_per_point.csv", index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1265940902021773, 'fraction_numerical': 0.004976671850699844, 'mean_word_length': 4.900917431192661, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '623703', 'license': 'MIT', 'n_tokens_mistral': 1111, 'n_tokens_neox': 1066, 'n_words': 196, 'path': 'EUCQ Analysis/Chord Plot.ipynb', 'repo_name': 'mansenfranzen/notebooks', 'size': '3215'}