<jupyter_start><jupyter_text>Heroes Of Pymoli Data Analysis* Of the 780 active players, the vast majority are male (83.59%). There also exists, a smaller, but notable proportion of female players (14.49%).* Peak age demographic falls between the ages of 23-30 (29.10%) with secondary groups falling between 31-35 (19.87%), and 18-22 (11.79%).  * Item 92, Final Critic was both the most popular and most profitable item with a purchase count of 13 at 4.61 per unit for a total purchase value of 59.99. -----  Note* Instructions have been included for each segment. You do not have to follow them exactly, but they are included to help you think through the steps.<jupyter_code># Dependencies and Setup
import pandas as pd
import numpy as np

# Read Purchasing File and store into Pandas data frame
purchase_data = pd.read_csv('/Users/danny_delatorre/Desktop/Data Bootcamp/Pending Homework/pandas-challenge/HeroesOfPymoli/purchase_data.csv')<jupyter_output><empty_output><jupyter_text>Player Count * Display the total number of players<jupyter_code># Display the total number of players

player_count_df = pd.DataFrame({'Total Players':[player_count]})

player_count_df<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>#Run basic calculations to obtain number of... unique items, average price, etc.

# unique items
unique_items = purchase_data['Item ID'].nunique()

# average price
average_price = purchase_data['Price'].mean()

# total purchases
total_purchases = purchase_data['Purchase ID'].count()

# total revenue
total_revenue = purchase_data['Price'].sum()


# Create a summary data frame to hold the results
total_purchases_df = pd.DataFrame({'Unique Items':[unique_items], 'Average Price':[average_price], 
                                   '# of Purchases':[total_purchases], 'Revenue':[total_revenue]})

total_purchases_df<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># Gender Demographics
# Percentage and Count of Male Players - Percentage and Count of Female Players - Percentage and Count of Other / Non-Disclosed
player_count = purchase_data['SN'].count()

gender_count = purchase_data['Gender'].value_counts()

gender_percent = gender_count/(player_count)*100

rounded_percent = gender_percent.round(2)

# output dataframe
gender_demo_df = pd.DataFrame({'Players Percentage':rounded_percent, 'Player Count':gender_count})

# give index a title 
gender_demo_df.index.name = 'Gender'

# align all df headers 
gender_demo_df.columns.name = gender_demo_df.index.name
gender_demo_df.index.name = None

# print df
gender_demo_df<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># Run basic calculations to obtain purchase count, avg. purchase price, avg. purchase total per person etc. by gender
player_count = purchase_data['SN'].count()

purchase_count = purchase_data.groupby(['Gender']).count()['Price']

average_purchase_price = purchase_data.groupby(['Gender']).mean()['Price']

purchase_total = purchase_data.groupby(['Gender']).sum()['Price']

purchase_total_per_person = (purchase_total / player_count)


# drop duplicates
purchase_data.drop_duplicates(inplace=True)


# Create a summary data frame to hold the results
gender_summary_df = pd.DataFrame({'Purchase Count':purchase_count,
                             'Avg. Purchase Price':average_purchase_price.round(2),
                                 'Avg. Purchase Total': purchase_total_per_person})

# align all df headers 
gender_summary_df.columns.name = gender_summary_df.index.name
gender_summary_df.index.name = None

# print df
gender_summary_df<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># Establish Bins For Ages
bins = [0, 12, 13, 18, 23, 31, 36, 40]
bin_labels = ['0-12', '13-17', '18-22', '23-30', '31-35', '36-40', '40+']

# Categorize the existing players using the age bins. Hint: use pd.cut()
age_ranges = purchase_data['Age Group'] = pd.cut(purchase_data['Age'], bins, labels = bin_labels)
age_ranges_df = pd.DataFrame({'Age Group':age_ranges})

# Calculate the numbers and percentages by age group - find count and percents essentially
players_count = len(purchase_data.index)

age_groups = purchase_data.groupby('Age Group')

age_total_count = age_groups['SN'].nunique()

percentages_by_age_group = (age_total_count/players_count) * 100

# Create a summary data frame to hold the results - Optional: round the percentage column to two decimal points (.round(2))
age_demographics_df = pd.DataFrame({'% of Players': percentages_by_age_group.round(2), 'Player Count': age_total_count})

# align all df headers 
age_demographics_df.columns.name = age_demographics_df.index.name
age_demographics_df.index.name = None

# Display Age Demographics Table
age_demographics_df<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># Establish Bins For Ages
bins = [0, 12, 13, 18, 23, 31, 36, 40]
bin_labels = ['0-12', '13-17', '18-22', '23-30', '31-35', '36-40', '40+']

# Categorize the existing players using the age bins. Hint: use pd.cut()
age_ranges = purchase_data['Age Group'] = pd.cut(purchase_data['Age'], bins, labels = bin_labels)
age_ranges_df = pd.DataFrame({'Age Group':age_ranges})

# Run basic calculations to obtain purchase count, avg. purchase price, avg. purchase total per person etc. in the table below
purchase_count = purchase_data.groupby(['Age Group']).count()['Price']

average_purchase_price = purchase_data.groupby(['Age Group']).mean()['Price']

# purchase total
purchase_total_per_person = purchase_data.groupby(['Age Group']).sum()['Price']

purchase_data.drop_duplicates(inplace=True)

# Create a summary data frame to hold the results
puchasing_analysis_df = pd.DataFrame({'Purchase Count':purchase_count,
                             'Average Price':average_purchase_price.round(2),
                                 'Purchase Total': purchase_total_per_person})

# Give the displayed data cleaner formatting
puchasing_analysis_df.columns.name = puchasing_analysis_df.index.name
puchasing_analysis_df.index.name = None

# Display the summary data frame
puchasing_analysis_df<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># Run basic calculations to obtain the results in the table below
transaction_count = purchase_data.groupby(['SN']).count()['Price']

total_spent = purchase_data.groupby(['SN']).sum()['Price']

# Create a summary data frame to hold the results
top_spenders_df = pd.DataFrame({'Transaction Count': transaction_count, 'Purchase Value': total_spent})

# Sort the total purchase value column in descending order
top_spenders_df = top_spenders_df.sort_values('Transaction Count', ascending=False)

# Optional: give the displayed data cleaner formatting
top_spenders_df.columns.name = top_spenders_df.index.name
top_spenders_df.index.name = None

# Display a preview of the summary data frame
top_spenders_df.head()<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>#Retrieve the Item ID, Item Name, and Item Price columns

retrieve_items = purchase_data[['Item ID', 'Item Name', 'Price']]

# Group by Item ID and Item Name.
item_data = most_popular_items.groupby(['Item ID', 'Item Name'])

# Perform calculations to obtain...

# purchase count
purchase_item_count = item_data['Price'].count()

# total purchase value
purchase_value = item_data['Price'].sum()

# & item price 
item_price = (purchase_value/purchase_item_count)

# Create a summary data frame to hold the results
most_popular_items_df = pd.DataFrame({'Purchase Count': purchase_item_count, 'Item Price': item_price.round(2), 'Total Purchase Value': purchase_value})

# Sort the purchase count column in descending order
most_popular_items_df = most_popular_items_df.sort_values('Purchase Count', ascending=False)

# Display a preview of the summary data frame
most_popular_items_df.head()<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># Sort the above table by total purchase value in descending order

most_profitable_items_df = most_popular_items_df.sort_values(by = ['Total Purchase Value'],ascending = False)

most_profitable_items_df = most_popular_items_df.drop(labels = ['Purchase Count','Item Price'],axis = 1)

# Display a preview of the data frame - Top 10 

most_profitable_items_df.head(10)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09168999131357977, 'fraction_numerical': 0.013801756587202008, 'mean_word_length': 5.6465683130211675, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '417308', 'license': 'ADSL', 'n_tokens_mistral': 3201, 'n_tokens_neox': 2981, 'n_words': 1027, 'path': 'HeroesOfPymoli/HeroesOfPymoli.ipynb', 'repo_name': 'danny-delatorre/pandas-challenge', 'size': '10361'}