<jupyter_start><jupyter_text>Player Count * Display the total number of players<jupyter_code># Calculating length of unique screen names "SN" for total players
total_players = len(purchase_data["SN"].unique())

# Creating DataFrame for Total Players
df1 = pd.DataFrame({"Total Players": [total_players]})
df1<jupyter_output><empty_output><jupyter_text>Purchasing Analysis (Total) * Run basic calculations to obtain number of unique items, average price, etc.* Create a summary data frame to hold the results* Optional: give the displayed data cleaner formatting* Display the summary data frame<jupyter_code># Running basic calculations for number of unique items, average price, number of purchases, and total  revenue
unique_items = len(purchase_data["Item ID"].unique())
average_price = purchase_data["Price"].mean()
number_purchase = purchase_data["Purchase ID"].count()
total_revenue = purchase_data["Price"].sum()

# Creating DataFrame for Purchasing Analysis (Total)
df2 = pd.DataFrame(
    {
        "Number of Unique Items": [unique_items],
        "Average Price": [average_price],
        "Number of Purchases": [number_purchase],
        "Total Revenue": [total_revenue],
    }
)

# Formatting average price and total revenue for currency $
df2.style.format({"Average Price": "${:,.2f}", "Total Revenue": "${:,.2f}"})<jupyter_output><empty_output><jupyter_text>Gender Demographics * Percentage and Count of Male Players* Percentage and Count of Female Players* Percentage and Count of Other / Non-Disclosed<jupyter_code># Grouping purchase_data by gender
gender_group = purchase_data.groupby(["Gender"])

# Calculating count of unique screen names "SN", i.e. count of players by gender
player_count_gender = gender_group["SN"].nunique()

# Calculating percentage of players by gender
player_percent_gender = (player_count_gender / total_players) * 100

# Creating DataFrame for Gender Demographics
df3 = pd.DataFrame(
    {
        "Total Count": player_count_gender,
        "Percentage of Players": player_percent_gender,
    }
)

# Setting index, sorting by "Total Count" in descending order, and formatting percentage of players
df3.index.name = None
df3.sort_values(["Total Count"], ascending=False).style.format(
    {"Percentage of Players": "{:,.2f}%"}
)<jupyter_output><empty_output><jupyter_text>Purchasing Analysis (Gender) * Run basic calculations to obtain purchase count, avg. purchase price, avg. purchase total per person etc. by gender* Create a summary data frame to hold the results* Optional: give the displayed data cleaner formatting* Display the summary data frame<jupyter_code># Running basic calculation for purchase count by gender
purchase_count_gender = gender_group["Purchase ID"].count()

# Running basic calculation for average purchase price by gender
average_price_gender = gender_group["Price"].mean()

# Running basic calculation for total purchase value by gender
total_value_gender = gender_group["Price"].sum()

# Running basic calculation for average total purchase per person by gender
avg_per_person_gender = total_value_gender / player_count_gender

# Creating DataFrame for Purchasing Analysis (Gender)
df4 = pd.DataFrame(
    {
        "Purchase Count": purchase_count_gender,
        "Average Purchase Price": average_price_gender,
        "Total Purchase Value": total_value_gender,
        "Avg Total Purchase per Person": avg_per_person_gender,
    }
)

# Setting index and formatting for currency $
df4.index.name = "Gender"
df4.style.format(
    {
        "Average Purchase Price": "${:,.2f}",
        "Total Purchase Value": "${:,.2f}",
        "Avg Total Purchase per Person": "${:,.2f}",
    }
)<jupyter_output><empty_output><jupyter_text>Age Demographics * Establish bins for ages* Categorize the existing players using the age bins. Hint: use pd.cut()* Calculate the numbers and percentages by age group* Create a summary data frame to hold the results* Optional: round the percentage column to two decimal points* Display Age Demographics Table<jupyter_code># Creating bins for ages
age_bins = [0, 9.90, 14.90, 19.90, 24.90, 29.90, 34.90, 39.90, 9999]
age_labels = ["<10", "10-14", "15-19", "20-24", "25-29", "30-34", "35-39", "40+"]

# Assigning and sorting age data into age_bins and age_labels
purchase_data["Age Ranges"] = pd.cut(purchase_data["Age"], age_bins, labels=age_labels)

# Grouping updated purchase_data by age
age_group = purchase_data.groupby(["Age Ranges"])

# Calculating total number of players by age
player_count_age = age_group["SN"].nunique()

# Calculating percentage of players by age
player_percent_age = (player_count_age / total_players) * 100

# Creating DataFrame for Age Demographics
df5 = pd.DataFrame(
    {"Total Count": player_count_age, "Percentage of Players": player_percent_age,}
)

# Setting index and formatting percentage of players
df5.index.name = None
df5.style.format({"Percentage of Players": "{:,.2f}%"})<jupyter_output><empty_output><jupyter_text>Purchasing Analysis (Age) * Bin the purchase_data data frame by age* Run basic calculations to obtain purchase count, avg. purchase price, avg. purchase total per person etc. in the table below* Create a summary data frame to hold the results* Optional: give the displayed data cleaner formatting* Display the summary data frame<jupyter_code># Running basic calculation for purchase count by age
purchase_count_age = age_group["Purchase ID"].count()

# Running basic calculation for average purchase price by age
average_price_age = age_group["Price"].mean()

# Running basic calculation for total purchase value by age
total_value_age = age_group["Price"].sum()

# Running basic calculation for average total purchase per person by age
average_per_person_age = total_value_age / player_count_age

# Creating DataFrame for Purchasing Analysis (Age)
df6 = pd.DataFrame(
    {
        "Purchase Count": purchase_count_age,
        "Average Purchase Price": average_price_age,
        "Total Purchase Value": total_value_age,
        "Avg Total Purchase per Person": average_per_person_age,
    }
)

# Setting index and formatting for currency $
df6.index.name = "Age Ranges"
df6.style.format(
    {
        "Average Purchase Price": "${:,.2f}",
        "Total Purchase Value": "${:,.2f}",
        "Avg Total Purchase per Person": "${:,.2f}",
    }
)<jupyter_output><empty_output><jupyter_text>Top Spenders * Run basic calculations to obtain the results in the table below* Create a summary data frame to hold the results* Sort the total purchase value column in descending order* Optional: give the displayed data cleaner formatting* Display a preview of the summary data frame<jupyter_code># Grouping purchase_data by screen names ("SN")
sn_group = purchase_data.groupby("SN")

# Calculating purchase count by "SN"
purchase_count_sn = sn_group["Purchase ID"].count()

# Calculating average purchase price by "SN"
average_price_sn = sn_group["Price"].mean()

# Calculating total purchase value by "SN"
total_value_sn = sn_group["Price"].sum()

# Creating DataFrame for Top Spenders
df7 = pd.DataFrame(
    {
        "Purchase Count": purchase_count_sn,
        "Average Purchase Price": average_price_sn,
        "Total Purchase Value": total_value_sn,
    }
)

# sorting top 5 spenders by "Total Purchase Value" in descending order and formatting for currency $
df7.sort_values(["Total Purchase Value"], ascending=False).head(5).style.format(
    {
        "Average Purchase Total": "${:,.2f}",
        "Average Purchase Price": "${:,.2f}",
        "Total Purchase Value": "${:,.2f}",
    }
)<jupyter_output><empty_output><jupyter_text>Most Popular Items * Retrieve the Item ID, Item Name, and Item Price columns* Group by Item ID and Item Name. Perform calculations to obtain purchase count, item price, and total purchase value* Create a summary data frame to hold the results* Sort the purchase count column in descending order* Optional: give the displayed data cleaner formatting* Display a preview of the summary data frame<jupyter_code># Grouping purchase_data by item ID and item name
item_group = purchase_data.groupby(["Item ID", "Item Name"])

# Calculating item purchase count
item_purchase_count = item_group["SN"].count()

# Calculating item total purchase value
item_total_value = item_group["Price"].sum()

# Calculating item price
item_price = item_total_value / item_purchase_count

# Creating DataFrame for Most Popular Items
df8 = pd.DataFrame(
    {
        "Purchase Count": item_purchase_count,
        "Item Price": item_price,
        "Total Purchase Value": item_total_value,
    }
)

# Sorting 5 most popular items by "Purchase Count" in descending order and formatting for currency $
df8.sort_values(["Purchase Count"], ascending=False).head(5).style.format(
    {"Item Price": "${:,.2f}", "Total Purchase Value": "${:,.2f}"}
)<jupyter_output><empty_output><jupyter_text>Most Profitable Items * Sort the above table by total purchase value in descending order* Optional: give the displayed data cleaner formatting* Display a preview of the data frame<jupyter_code># Creating DataFrame for Most Profitable Items
df9 = pd.DataFrame(
    {
        "Purchase Count": item_purchase_count,
        "Item Price": item_price,
        "Total Purchase Value": item_total_value,
    }
)

# Sorting 5 most profitable items by "Total Purchase Value" in descending order and formatting for currency $
df9.sort_values(["Total Purchase Value"], ascending=False).head(5).style.format(
    {"Item Price": "${:,.2f}", "Total Purchase Value": "${:,.2f}"}
)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10181019148268285, 'fraction_numerical': 0.011614523385999791, 'mean_word_length': 4.9625701809107925, 'pattern_counts': {'":': 43, '<': 38, '<?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': '627176', 'license': 'ADSL', 'n_tokens_mistral': 2881, 'n_tokens_neox': 2691, 'n_words': 976, 'path': 'HeroesOfPymoli/HeroesOfPymoli_Pandas.ipynb', 'repo_name': 'sabrinasaleh/pandas-challenge', 'size': '9557'}