<jupyter_start><jupyter_text>Player Count<jupyter_code>total_players = purchase_data['SN'].nunique()
players = pd.DataFrame({"Total Players": total_players},index= [0])
players<jupyter_output><empty_output><jupyter_text>Purchasing Analysis (Total)<jupyter_code>unique_items = purchase_data['Item Name'].nunique()
avg_price = purchase_data["Price"].mean()
avg_price = "${:.2f}".format(avg_price)
num_purchases = len(purchase_data['Purchase ID'])
revenue = purchase_data['Price'].sum()
revenue = "${:,.2f}".format(revenue)
items_summary = pd.DataFrame({"Numbrer of Unique Items": unique_items,
                             "Average Price": avg_price,
                             "Number of Purchases": num_purchases,
                             "Total Revenue": revenue}, index= ["Totals"])
items_summary<jupyter_output><empty_output><jupyter_text>Gender Demographics<jupyter_code>male_count = purchase_data[purchase_data["Gender"]=="Male"].nunique()
male_count = male_count['SN']
female_count = purchase_data[purchase_data["Gender"]=="Female"].nunique()
female_count = female_count['SN']
other_count =purchase_data[purchase_data["Gender"]=="Other / Non-Disclosed"].nunique()
other_count = other_count['SN']
male_per = (male_count/total_players)
female_per = female_count/total_players
other_per = other_count/total_players
total_purchase = purchase_data.groupby("Gender")['Price'].sum()
male_count
G_demo = pd.DataFrame({"Total Count": [male_count, female_count, other_count,], 
                       "Percentage": [male_per, female_per, other_per]},index=["Male", "Female", "Other"])
G_demo['Percentage']=G_demo["Percentage"].astype(float).map("{:,.2%}".format)
G_demo<jupyter_output><empty_output><jupyter_text>Purchasing Analysis (Gender)<jupyter_code>gender_count=purchase_data.groupby('Gender').SN.nunique()
total_count = purchase_data['Gender'].value_counts()
avg_purchase =purchase_data.groupby('Gender')['Price'].mean()
total_purchase = purchase_data.groupby("Gender")['Price'].sum()
avg_person = total_purchase/gender_count

purch_gender = pd.DataFrame({"Purchase Count": total_count,
                            "Average Purchase": avg_purchase,
                            "Total Purchase Price": total_purchase,
                            "Average Total Per Person":avg_person}, index = ['Male', 'Female', 'Other / Non-Disclosed'])
purch_gender['Average Purchase']=purch_gender['Average Purchase'].map("${:.2f}".format)
purch_gender["Total Purchase Price"]=purch_gender["Total Purchase Price"].map("${:.2f}".format)
purch_gender["Average Total Per Person"]=purch_gender[ "Average Total Per Person"].map("${:.2f}".format)
purch_gender
purchase_data.head()
bins=[0,9.99,14.99,19.99,24.99,29.99,34.99,39.99,99]
purch_label = ["<10", "10-14", "15-19", "20-24", "25-29", "30-34", "35-39", "40+"]

pd.cut(purchase_data['Age'],bins, labels= purch_label, include_lowest= True)
purchase_bin = purchase_data.drop_duplicates(subset="SN", keep="first")
purchase_bin['Percentage of Players']= pd.cut(purchase_data['Age'],bins, labels= purch_label, include_lowest= True)

ageGroup = purchase_bin['Percentage of Players'].value_counts()
bin_group = purchase_bin.groupby('Percentage of Players')
total_players = len(purchase_bin["SN"].value_counts())
age_count = bin_group['SN'].nunique()
age_per = (age_count/total_players)
age_per = age_per.astype(float).map("{:.2%}".format)<jupyter_output><empty_output><jupyter_text>Age Demographics<jupyter_code>age_demo = pd.DataFrame({"Total Count": ageGroup,
                        "Percentage of Players": age_per},index=["<10", "10-14", "15-19", "20-24", "25-29", "30-34", "35-39","40+"])
age_demo
count = len(purchase_bin['SN'].value_counts())
pur_count = bin_group['Item Name'].count()
purchase_age = purchase_data

purchase_age['age_range']=pd.cut(purchase_data['Age'],bins, labels= purch_label, include_lowest= True)
age_count=purchase_data.groupby("age_range").SN.nunique()
age_group = purchase_age.groupby('age_range')
pur_count = age_group['Purchase ID'].count()
avg_price =purchase_age.groupby('age_range')['Price'].mean()
to_purchase =purchase_age.groupby("age_range")['Price'].sum()
to_purchase
avg_person = to_purchase/age_count<jupyter_output><empty_output><jupyter_text>Purchasing Analysis (Age)<jupyter_code>age_analysis = pd.DataFrame({"Purchase Count": pur_count,
                        "Average Purchase Price": avg_price,
                            "Total Purchase Value": to_purchase,
                            "Avg Total Purchase per Person": avg_person},index=["<10", "10-14", "15-19", "20-24", "25-29", "30-34", "35-39","40+"])
age_analysis["Average Purchase Price"]= age_analysis["Average Purchase Price"].map("${:,.2f}".format)
age_analysis["Total Purchase Value"]= age_analysis["Total Purchase Value"].map("${:,.2f}".format)
age_analysis["Avg Total Purchase per Person"]= age_analysis["Avg Total Purchase per Person"].map("${:,.2f}".format)
age_analysis<jupyter_output><empty_output><jupyter_text>TOP SPENDER<jupyter_code>spend =purchase_age.groupby("SN")
player_count = spend['Purchase ID'].count().sort_values(ascending=False)
player_avg = spend["Price"].mean().sort_values(ascending=False)
player_sum =spend["Price"].sum().sort_values(ascending =False)
top_spend = pd.DataFrame({"Purchase Count": player_count,
                         "Average Purchase Price": player_avg,
                         "Total Purchase Value": player_sum})
top_spend =top_spend.sort_values("Total Purchase Value", ascending=False).head()
top_spend['Average Purchase Price']=top_spend['Average Purchase Price'].map("${:,.2f}".format)
top_spend['Total Purchase Value']=top_spend['Total Purchase Value'].map("${:,.2f}".format)
top_spend<jupyter_output><empty_output><jupyter_text>Most Popular Items<jupyter_code>popular = purchase_data[["Item ID", "Item Name", "Price"]]
popular_gp = popular.groupby(['Item ID', "Item Name"])
popular_count = popular_gp['Price'].count()
popular_tvalue = popular_gp['Price'].sum()
popular_cost = popular_tvalue/popular_count 
popular_items = pd.DataFrame({"Purchase Count": popular_count,
                              "Item Price": popular_cost,
                             "Total Purchase Value": popular_tvalue})
popular_items1 =popular_items.sort_values("Purchase Count", ascending=False).head()
popular_items1["Item Price"]=popular_items["Item Price"].map("${:,.2f}".format)
popular_items1["Total Purchase Value"]=popular_items["Total Purchase Value"].map("${:,.2f}".format)
popular_items1<jupyter_output><empty_output><jupyter_text>Most Profitable Item<jupyter_code>popular_items =popular_items.sort_values("Total Purchase Value", ascending=False).head()
popular_items["Item Price"]=popular_items["Item Price"].map("${:,.2f}".format)
popular_items["Total Purchase Value"]=popular_items["Total Purchase Value"].map("${:,.2f}".format)
popular_items<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1658657346730741, 'fraction_numerical': 0.019659239842726082, 'mean_word_length': 6.146722164412071, 'pattern_counts': {'":': 23, '<': 40, '<?xml version=': 0, '>': 37, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '75420', 'license': 'MIT', 'n_tokens_mistral': 2440, 'n_tokens_neox': 2258, 'n_words': 352, 'path': 'HeroesOfPymoli/HeroesOfPymoly.ipynb', 'repo_name': 'gportes24/pandas-challenge', 'size': '6867'}