Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Three observable trends based on the data

  1. Most players are males by a large amount.
  2. Ages 20 - 24 make the most purchases.
  3. The average item purchase price is $2.82 to $3.25.
# Import modules
import pandas as pd
import json
import os
# Load JSON File
file = os.path.join('purchase_data.json')

data = pd.read_json(file)
# Check JSON File
data.head()
<style> .dataframe thead tr:only-child th { text-align: right; }
.dataframe thead th {
    text-align: left;
}

.dataframe tbody tr th {
    vertical-align: top;
}
</style>
Age Gender Item ID Item Name Price SN
0 38 Male 165 Bone Crushing Silver Skewer 3.37 Aelalis34
1 21 Male 119 Stormbringer, Dark Blade of Ending Misery 2.32 Eolo46
2 34 Male 174 Primitive Blade 2.46 Assastnya25
3 21 Male 92 Final Critic 1.36 Pheusrical25
4 23 Male 63 Stormfury Mace 1.27 Aela59

Player Count

# Player Count
# Total Number of Players

player_count = len(data['SN'].unique())

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

players_df.set_index('Total Players', inplace = True)
players_df
<style> .dataframe thead tr:only-child th { text-align: right; }
.dataframe thead th {
    text-align: left;
}

.dataframe tbody tr th {
    vertical-align: top;
}
</style>
Total Players
573

Purchasing Analysis (Total)

# Purchasing Analysis (Total)
# Number of Unique Items
# Average Purchase Price
# Total Number of Purchases
# Total Revenue

no_dup_items = data.drop_duplicates(['Item ID'], keep = 'last')

total_unique = len(no_dup_items)

total_pur = data['Price'].count()

total_rev = round(data['Price'].sum(),2)

avg_price = round(total_rev/total_pur, 2)

pur_analysis = pd.DataFrame([{
    
    "Number of Unique Items": total_unique,
    'Average Purchase Price': avg_price,
    'Total Purchases': total_pur,
    'Total Revenue': total_rev
}])

pur_analysis.style.format({'Average Purchase Price': '${:.2f}', 'Total Revenue': '${:,.2f}'})
<style type="text/css" > </style>
Average Purchase Price Number of Unique Items Total Purchases Total Revenue
0 $2.93 183 780 $2,286.33

Gender Demographics

# Gender Demographics
# Percentage and Count of Male Players
# Percentage and Count of Female Players
#Percentage and Count of Other / Non-Disclosed

no_dup_players = data.drop_duplicates(['SN'], keep ='last')

gender_counts = no_dup_players['Gender'].value_counts().reset_index()

gender_counts['% of Players'] = gender_counts['Gender']/player_count * 100

gender_counts.rename(columns = {'index': 'Gender', 'Gender': '# of Players'}, inplace = True)

gender_counts.set_index(['Gender'], inplace = True)

gender_counts.style.format({"% of Players": "{:.1f}%"})
<style type="text/css" > </style>
# of Players % of Players
Gender
Male 465 81.2%
Female 100 17.5%
Other / Non-Disclosed 8 1.4%

Purchasing Analysis (Gender)

# Purchasing Analysis (Gender)
# The below each broken by gender
# Purchase Count
# Average Purchase Price
# Total Purchase Value
# Normalized Totals

count_by_gen = pd.DataFrame(data.groupby('Gender')['Gender'].count())

total_by_gen = pd.DataFrame(data.groupby('Gender')['Price'].sum())

analysis_gen = pd.merge(count_by_gen, total_by_gen, left_index = True, right_index = True)

analysis_gen.rename(columns = {'Gender': '# of Purchases', 'Price':'Total Purchase Value'}, inplace=True)

analysis_gen['Average Purchase Price'] = analysis_gen['Total Purchase Value']/analysis_gen['# of Purchases']

analysis_gen = analysis_gen.merge(gender_counts, left_index = True, right_index = True)

analysis_gen['Normalized Totals'] = analysis_gen['Total Purchase Value']/analysis_gen['# of Players']
analysis_gen

del analysis_gen['% of Players']
del analysis_gen['# of Players']

analysis_gen.style.format({'Total Purchase Value': '${:.2f}', 'Average Purchase Price': '${:.2f}', 'Normalized Totals': '${:.2f}'})
<style type="text/css" > </style>
# of Purchases Total Purchase Value Average Purchase Price Normalized Totals
Gender
Female 136 $382.91 $2.82 $3.83
Male 633 $1867.68 $2.95 $4.02
Other / Non-Disclosed 11 $35.74 $3.25 $4.47

Age Demographics

# Age Demographics
# The below each broken into bins of 4 years (i.e. <10, 10-14, 15-19, etc.)
# Purchase Count
# Average Purchase Price
# Total Purchase Value
# Normalized Totals

data.loc[(data['Age'] < 10), 'age_bin'] = "< 10"
data.loc[(data['Age'] >= 10) & (data['Age'] <= 14), 'age_bin'] = "10 - 14"
data.loc[(data['Age'] >= 15) & (data['Age'] <= 19), 'age_bin'] = "15 - 19"
data.loc[(data['Age'] >= 20) & (data['Age'] <= 24), 'age_bin'] = "20 - 24"
data.loc[(data['Age'] >= 25) & (data['Age'] <= 29), 'age_bin'] = "25 - 29"
data.loc[(data['Age'] >= 30) & (data['Age'] <= 34), 'age_bin'] = "30 - 34"
data.loc[(data['Age'] >= 35) & (data['Age'] <= 39), 'age_bin'] = "35 - 39"
data.loc[(data['Age'] >= 40), 'age_bin'] = "> 40"

count_age = pd.DataFrame(data.groupby('age_bin')['SN'].count())

avg_price_age = pd.DataFrame(data.groupby('age_bin')['Price'].mean())

tot_pur_age = pd.DataFrame(data.groupby('age_bin')['Price'].sum())

no_dup_age = pd.DataFrame(data.drop_duplicates('SN', keep = 'last').groupby('age_bin')['SN'].count())

merge_age = pd.merge(count_age, avg_price_age, left_index = True, right_index = True).merge(tot_pur_age, left_index = True, right_index = True).merge(no_dup_age, left_index = True, right_index = True)

merge_age.rename(columns = {"SN_x": "# of Purchases", "Price_x": "Average Purchase Price", "Price_y": "Total Purchase Value", "SN_y": "# of Purchasers"}, inplace = True)

merge_age['Normalized Totals'] = merge_age['Total Purchase Value']/merge_age['# of Purchasers']

merge_age.index.rename("Age", inplace = True)

merge_age.style.format({'Average Purchase Price': '${:.2f}', 'Total Purchase Value': '${:.2f}', 'Normalized Totals': '${:.2f}'})
<style type="text/css" > </style>
# of Purchases Average Purchase Price Total Purchase Value # of Purchasers Normalized Totals
Age
10 - 14 35 $2.77 $96.95 23 $4.22
15 - 19 133 $2.91 $386.42 100 $3.86
20 - 24 336 $2.91 $978.77 259 $3.78
25 - 29 125 $2.96 $370.33 87 $4.26
30 - 34 64 $3.08 $197.25 47 $4.20
35 - 39 42 $2.84 $119.40 27 $4.42
< 10 28 $2.98 $83.46 19 $4.39
> 40 17 $3.16 $53.75 11 $4.89

Top Spenders

# Top Spenders
# Identify the the top 5 spenders in the game by total purchase value, then list (in a table):
# SN
# Purchase Count
# Average Purchase Price
# Total Purchase Value

purchase_amt_by_SN = pd.DataFrame(data.groupby('SN')['Price'].sum())
num_purchase_by_SN = pd.DataFrame(data.groupby('SN')['Price'].count())
avg_purchase_by_SN = pd.DataFrame(data.groupby('SN')['Price'].mean())

merged_top5 = pd.merge(purchase_amt_by_SN, num_purchase_by_SN, left_index = True, right_index = True).merge(avg_purchase_by_SN, left_index=True, right_index=True)

merged_top5.rename(columns = {'Price_x': 'Total Purchase Value', 'Price_y':'Purchase Count', 'Price':'Average Purchase Price'}, inplace = True)

merged_top5.sort_values('Total Purchase Value', ascending = False, inplace=True)

merged_top5 = merged_top5.head()

merged_top5.style.format({'Total Purchase Value': '${:.2f}', 'Average Purchase Price': '${:.2f}'})
<style type="text/css" > </style>
Total Purchase Value Purchase Count Average Purchase Price
SN
Undirrala66 $17.06 5 $3.41
Saedue76 $13.56 4 $3.39
Mindimnya67 $12.74 4 $3.18
Haellysu29 $12.73 3 $4.24
Eoda93 $11.58 3 $3.86

Most Popular Items

# Most Popular Items
# Identify the 5 most popular items by purchase count, then list (in a table):
# Item ID
# Item Name
# Purchase Count
# Item Price
# Total Purchase Value

top5_items_ID = pd.DataFrame(data.groupby('Item ID')['Item ID'].count())

top5_items_ID.sort_values('Item ID', ascending = False, inplace = True)

top5_items_ID = top5_items_ID.iloc[0:5][:]

top5_items_total = pd.DataFrame(data.groupby('Item ID')['Price'].sum())

top5_items = pd.merge(top5_items_ID, top5_items_total, left_index = True, right_index = True)

no_dup_items = data.drop_duplicates(['Item ID'], keep = 'last')

top5_merge_ID = pd.merge(top5_items, no_dup_items, left_index = True, right_on = 'Item ID')

top5_merge_ID = top5_merge_ID[['Item ID', 'Item Name', 'Item ID_x', 'Price_y', 'Price_x']]

top5_merge_ID.set_index(['Item ID'], inplace = True)

top5_merge_ID.rename(columns =  {'Item ID_x': 'Purchase Count', 'Price_y': 'Item Price', 'Price_x': 'Total Purchase Value'}, inplace=True)

top5_merge_ID.style.format({'Item Price': '${:.2f}', 'Total Purchase Value': '${:.2f}'})
<style type="text/css" > </style>
Item Name Purchase Count Item Price Total Purchase Value
Item ID
39 Betrayal, Whisper of Grieving Widows 11 $2.35 $25.85
84 Arcane Gem 11 $2.23 $24.53
31 Trickster 9 $2.07 $18.63
175 Woeful Adamantite Claymore 9 $1.24 $11.16
13 Serenity 9 $1.49 $13.41

Most Profitable Items

# Most Profitable Items
# Identify the 5 most profitable items by total purchase value, then list (in a table):
# Item ID
# Item Name
# Purchase Count
# Item Price
# Total Purchase Value

top5_profit = pd.DataFrame(data.groupby('Item ID')['Price'].sum())
top5_profit.sort_values('Price', ascending = False, inplace = True)

top5_profit = top5_profit.iloc[0:5][:]

pur_count_profit = pd.DataFrame(data.groupby('Item ID')['Item ID'].count())

top5_profit = pd.merge(top5_profit, pur_count_profit, left_index = True, right_index = True, how = 'left')
top5_merge_profit = pd.merge(top5_profit, no_dup_items, left_index = True, right_on = 'Item ID', how = 'left')
top5_merge_profit = top5_merge_profit[['Item ID', 'Item Name', 'Item ID_x', 'Price_y','Price_x']]
top5_merge_profit.set_index(['Item ID'], inplace=True)
top5_merge_profit.rename(columns = {'Item ID_x': 'Purchase Count', 'Price_y': 'Item Price', 'Price_x': 'Total Purchase Value'}, inplace = True)
top5_merge_profit.style.format({'Item Price': '${:.2f}', 'Total Purchase Value': '${:.2f}'})
<style type="text/css" > </style>
Item Name Purchase Count Item Price Total Purchase Value
Item ID
34 Retribution Axe 9 $4.14 $37.26
115 Spectral Diamond Doomblade 7 $4.25 $29.75
32 Orenmir 6 $4.95 $29.70
103 Singed Scalpel 6 $4.87 $29.22
107 Splitter, Foe Of Subtlety 8 $3.61 $28.88

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages