<jupyter_start><jupyter_text>Heroes Of Pymoli Data Analysis* Of the 1163 active players, the vast majority are male (84%). There also exists, a smaller, but notable proportion of female players (14%).* Our peak age demographic falls between 20-24 (44.8%) with secondary groups falling between 15-19 (18.60%) and 25-29 (13.4%).  -----  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

# File to Load (Remember to Change These)
file_to_load = "Resources/purchase_data.csv"

# Read Purchasing File and store into Pandas data frame
purchase_data = pd.read_csv(file_to_load)
purchase_data<jupyter_output><empty_output><jupyter_text>Player Count * Display the total number of players<jupyter_code>df4 =list(set(purchase_data.SN))
df4
Total_Players = len(df4)
print(f'The total number of players are {Total_Players}')<jupyter_output>The total number of players are 576<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>purchase_data =purchase_data.rename(columns = {'Item Name':'Item_Name','Purchase ID':'Purchase_ID'})
#Find unique Values in the dataframe
item_list = list(purchase_data['Item_Name'].unique())
item_count =len(item_list)
#item_count
# Count the number of purchases
Number_of_Purchases =purchase_data['Purchase_ID'].count()
# Sum of the price 
Total_Revenue = purchase_data['Price'].sum()
# Average Values of the price
Average_price = (purchase_data['Price'].mean())
Average_price = round(Average_price,2)
# Display the values in Summary Dataframe
Summary_df1 = pd.DataFrame({"Number of Unique_Items":[item_count],
                              'Average_Price':[Average_price],
                              'Number_of_Purchases':[Number_of_Purchases],
                              'Total_Revenue':[Total_Revenue]})

# Format Values to display the amount in $ and 2 decimal places
Summary_df1["Average_Price"] = Summary_df1["Average_Price"].map("${:.2f}".format)
Summary_df1["Total_Revenue"] = Summary_df1["Total_Revenue"].map("${:.2f}".format)

# Column rename
Summary_df1.rename(columns = {'Average_Price':'Average Price','Total_Revenue':'Total Revenue','Number_of_Purchases':'Number of Purchases','Number of Unique_Items':'Number of Unique Items'},inplace = True)
Summary_df1<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># Create Player Demographics dataframe
player_demographics = purchase_data.loc[:, ["Gender", "SN", "Age"]]
player_demographics
# # Drop duplicates values in the dataframe
player_demographics = player_demographics.drop_duplicates()
# # Obtain Value Counts
gender_demographics = player_demographics['Gender'].value_counts()
gender_demographics
gender_demographics_percent = gender_demographics/Total_Players*100
gender_percent = gender_demographics_percent.round(2).map("{:.2f}%".format)
gender_demographics_df = pd.DataFrame({"Total Count":gender_demographics,"Percentage of Players":gender_percent})
gender_demographics_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>purchase_data_price = purchase_data.groupby("Gender")['Price'].sum()
purchase_data_count = purchase_data.groupby("Gender")['Price'].count()
purchase_data_avg= purchase_data.groupby("Gender")['Price'].mean().round(2).map("${:.2f}".format)
purchase_data_avg_per_person = (purchase_data_price/gender_demographics_df['Total Count']).round(2).map("${:.2f}".format)
purchase_analysis = pd.DataFrame({"Purchase Count":purchase_data_count,"Average Purchase Price":purchase_data_avg,
                                  "Total Purchase Value":purchase_data_price,
                                  "Avg Total Purchase Per Person": purchase_data_avg_per_person})
purchase_analysis<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>bins =[0,9,14,19,24,29,34,39,100]
group_names = ["<10","10-14","15-19","20-24","25-29","30-34","35-39","40+"]
player_demographics["Age Range"] = pd.cut(player_demographics["Age"], bins, labels=group_names)

Players_bin = player_demographics["Age Range"].value_counts()

Players_bin_Percentage = ((Players_bin/Total_Players)*100).map("{:.2f}%".format)
Players_bin_Percentage

new_df= pd.DataFrame({'Total Count':Players_bin,'Percentage of Players':Players_bin_Percentage}).sort_index()
new_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>bins =[0,9,14,19,24,29,34,39,100]
group_names = ["<10","10-14","15-19","20-24","25-29","30-34","35-39","40+"]
purchase_data["Age group"] = pd.cut(purchase_data["Age"], bins, labels=group_names, include_lowest=True)
purchase_total =purchase_data.groupby(["Age group"])['Price'].sum()
Purchase_average=purchase_data.groupby(["Age group"])['Price'].mean().round(2).map("${:.2f}".format)
Purchase_count=purchase_data.groupby(["Age group"])['Price'].count()
Purchase_total_per_person =(purchase_total/new_df['Total Count']).map("${:.2f}".format)
new_df1 = pd.DataFrame({'Purchase Count':Purchase_count,'Average Purchase Price':Purchase_average,
                       'Total Purchase Value':Purchase_average,
                       'Avg Total Purchase Per Person':Purchase_total_per_person})
new_df1<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>student_total =purchase_data.groupby(['SN'])['Price'].sum().map("${:.2f}".format)
student_Avg_price =purchase_data.groupby(['SN'])['Price'].mean().map("${:.2f}".format)
student_purchase_count =purchase_data.groupby(['SN'])['Price'].count()
new_df2 = pd.DataFrame({'Purchase Count':student_purchase_count,
                       'Average Purchase Price':student_Avg_price,
                        'Total Purchase Value':student_total})
new_df2_desc =new_df2.sort_values('Total Purchase Value', ascending = False)
new_df2_desc.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>item_value = purchase_data.loc[:,["Item ID","Item_Name", "Price"]]
item_price = item_value.groupby(['Item ID','Item_Name'])['Price'].sum().map("${:.2f}".format)
item_Avg = item_value.groupby(['Item ID','Item_Name'])['Price'].mean().map("${:.2f}".format)
item_count=item_value.groupby(['Item ID','Item_Name'])['Price'].count()
new_df4 = pd.DataFrame({'Purchase Count':item_count, 'Item Price':item_Avg,'Total Purchase Value':item_price})
new_df4<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>new_df5 = new_df4.sort_values('Total Purchase Value',ascending = False)
new_df5<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12006079027355623, 'fraction_numerical': 0.019639934533551555, 'mean_word_length': 6.471615720524017, 'pattern_counts': {'":': 7, '<': 42, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '93692', 'license': 'ADSL', 'n_tokens_mistral': 2752, 'n_tokens_neox': 2527, 'n_words': 686, 'path': 'HeroesOfPymoli/.ipynb_checkpoints/HeroesOfPymoli_starter-checkpoint.ipynb', 'repo_name': 'sdevulapalli9/pandas-challenge', 'size': '8554'}