<jupyter_start><jupyter_text>Study friend informationThis notebook looks at the players friend information.<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
api_calls_day = pd.Timestamp('2019-06-13')
churn_cutoff = api_calls_day - pd.Timedelta(3,'M')
df = pd.read_csv("player_friend_info_200k.csv",dtype={'steamid': str}).drop("Unnamed: 0", axis='columns')
df = df[pd.to_datetime(df['friend_since'], unit='s') < churn_cutoff]
df.head()
df.tail()
df.info()
df['steamid'].nunique()
df['steamid_orig'].nunique()
df['relationship'].nunique()
df = df.drop('relationship',axis='columns')
#df['Root'] = (df['steamid_orig'] == 76561197960434622)
df.head()
df.tail()
#First_tier = list(df[df['Root']]['steamid'])
#df['First_tier'] = df['steamid_orig'].apply(lambda x: x in First_tier)
#Second_tier = list(df[df['First_tier']]['steamid'])
#df['Second_tier'] = df['steamid_orig'].apply(lambda x: x in Second_tier)
#df['Third_tier'] = ((~df['Second_tier']) & (~df['First_tier']))
#df[df['Third_tier']]
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
df_num_Friends = (df.groupby('steamid_orig').count()['steamid']).to_frame()
df_num_Friends = df_num_Friends.reset_index()
df_num_Friends['num_Friends'] = df_num_Friends['steamid']
df_num_Friends[df_num_Friends['steamid_orig'] == 76561197960434622]
df_num_Friends = df_num_Friends.drop('steamid',axis='columns')
df_num_Friends['steamid'] = df_num_Friends['steamid_orig']
df_num_Friends = df_num_Friends.drop('steamid_orig',axis='columns')
df_num_Friends.head()
df_max = df.loc[df.groupby('steamid_orig')['friend_since'].idxmax()]
df_max = df_max.reset_index()
df_max.head()
df_max[df_max['steamid_orig'] == 76561197960434622]
df_max['newest_friend_time'] = df_max['friend_since']
df_max['newest_friend_steamid'] = df_max['steamid']
df_max = df_max.drop(['index','friend_since','steamid'],axis='columns')
df_max.head()
df_max['steamid'] = df_max['steamid_orig']
df_max = df_max.drop('steamid_orig',axis='columns')
df_max.head()
df_max.info()
df_max.nunique()
df_min = df.loc[df.groupby('steamid_orig')['friend_since'].idxmin()]
df_min = df_min.reset_index()
df_min.head()
df_min[df_min['steamid_orig'] == 76561197960434622]
df_min['oldest_friend_time'] = df_min['friend_since']
df_min['oldest_friend_steamid'] = df_min['steamid']
df_min = df_min.drop(['index','friend_since','steamid'],axis='columns')
df_min.head()
df_min['steamid'] = df_min['steamid_orig']
df_min = df_min.drop('steamid_orig',axis='columns')
df_min.head()

df_min.info()

df_min.nunique()
df_max.head()
df_min.head()
df_friend_extremes = df_max.merge(df_min,on=['steamid'],suffixes=('_max', '_min'))
#df_friend_extremes[df_friend_extremes['Root_max'] != df_friend_extremes['Root_min']]
#df_friend_extremes[df_friend_extremes['First_tier_max'] != df_friend_extremes['First_tier_min']]
#df_friend_extremes[df_friend_extremes['Second_tier_max'] != df_friend_extremes['Second_tier_min']]
df_friend_extremes.head()
#df_friend_extremes['Root'] = df_friend_extremes['Root_max']
#df_friend_extremes['First_tier'] = df_friend_extremes['First_tier_max']
#df_friend_extremes['Second_tier'] = df_friend_extremes['Second_tier_max']
#df_friend_extremes['Third_tier'] = df_friend_extremes['Third_tier_max']
#df_friend_extremes = df_friend_extremes.drop(['Root_max','Root_min','First_tier_max','First_tier_min','Second_tier_max','Second_tier_min','Third_tier_max','Third_tier_min'],axis='columns')
df_friend_extremes.head()
df_num_Friends.head()
df_friend_extremes.info()
df_num_Friends.info()
df_friend_summary = df_num_Friends.merge(df_friend_extremes,on='steamid')
df_friend_summary.info()
df_friend_summary.head()
sns.distplot(np.log(df_friend_summary['num_Friends']))
sns.heatmap(df.isnull(), cbar=False)
import datetime
# plot it
fig, ax = plt.subplots(1,1)
ax.hist(df_friend_summary[df_friend_summary['newest_friend_time'] > 1]['newest_friend_time'], bins=500, color='lightblue')
ax.xaxis.set_major_locator(mdates.YearLocator())
ax.xaxis.set_major_formatter(mdates.DateFormatter('%d.%m.%y'))
plt.show()
fig, ax = plt.subplots(1,1)
ax.hist(df_friend_summary[df_friend_summary['oldest_friend_time'] > 1]['oldest_friend_time'], bins=500, color='lightblue')
ax.xaxis.set_major_locator(mdates.YearLocator())
ax.xaxis.set_major_formatter(mdates.DateFormatter('%d.%m.%y'))
plt.show()
df_friend_summary.to_csv('200k_friend_summary.csv')
df_friend_summary['newest_friend_time'].max()
pd.to_datetime(1552494489,unit='s')
df[df['friend_since'] == 0]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17485739359368144, 'fraction_numerical': 0.023475208424747696, 'mean_word_length': 11.951704545454545, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 7, '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': '41514', 'license': 'MIT', 'n_tokens_mistral': 1939, 'n_tokens_neox': 1795, 'n_words': 201, 'path': 'Study_Friends.ipynb', 'repo_name': 'chmartin/SteamCommunity', 'size': '4558'}