Clash Royale Account Analysis¶

An exploratory analysis of a friend’s Clash Royale account using Python, pandas, and Matplotlib.

This project examines the card collection, compares remaining level steps across rarity and elixir-cost groups, and summarizes account performance.

Data is requested from the official Clash Royale API through the RoyaleAPI proxy. Rerunning the data-collection cells requires an API key; you can sign up for one here: https://developer.clashroyale.com/#/.

The displayed results reflect data retrieved on October 14, 2026. Future requests may return different account statistics.

In [ ]:
import requests
import pandas as pd
import matplotlib.pyplot as plt

#Prompt for the API key without displaying/hardcoding it
from getpass import getpass

#Configure the plot formatting
plt.rcParams.update({
    "font.size": 11,
    "axes.spines.top": False,
    "axes.spines.right": False,
})
In [2]:
API_KEY = getpass("Paste your Clash Royale API key: ")

headers = {
    "Accept": "application/json",
    "Authorization": "Bearer " + API_KEY
}

url = "https://proxy.royaleapi.dev/v1/players/%23J90CCL28Q"
Paste your Clash Royale API key:  ········
In [3]:
page = requests.get(url, headers=headers, timeout=20)
page.raise_for_status()

data = page.json()

account = pd.DataFrame([data])

account[["name", "trophies", "wins", "losses"]]
Out[3]:
name trophies wins losses
0 FreightTrain45 7283 655 458
In [ ]:
cards = pd.DataFrame(account.loc[0, "cards"])


cards = cards.loc[:, ["id", "name", "rarity", "level", "maxLevel", "count", "elixirCost"]].copy()

for column in ["level", "maxLevel", "count", "elixirCost"]:
    cards[column] = pd.to_numeric(
        cards[column],
        errors="raise",
    )

cards.head()
Out[ ]:
id name rarity level maxLevel count elixirCost
0 26000059 Royal Hogs rare 1 14 536 5.0
1 26000020 Giant Skeleton epic 5 11 3 6.0
2 26000047 Royal Recruits common 6 16 1037 7.0
3 26000041 Goblin Gang common 10 16 412 3.0
4 28000005 Freeze epic 5 11 18 4.0
In [5]:
print("Number of cards:", len(cards))

print("Duplicate card IDs:", cards["id"].duplicated().sum())

print("Missing values:")
print(cards.isna().sum())
Number of cards: 119
Duplicate card IDs: 0
Missing values:
id            0
name          0
rarity        0
level         0
maxLevel      0
count         0
elixirCost    1
dtype: int64
In [6]:
cards.loc[cards["elixirCost"].isna(), ["name", "rarity", "elixirCost"]]
Out[6]:
name rarity elixirCost
100 Mirror epic NaN

Card collection and level gaps¶

For each card, I calculate the level gap as the API’s reported maximum level minus its current level (maxLevel - level). A smaller gap means fewer level steps remaining to the reported cap.

Because rarities have different starting levels, this measure does not represent upgrades completed since unlocking, percentage completion, or resources invested.

In [7]:
cards["levels_below_cap"] = cards["maxLevel"] - cards["level"]

cards["at_reported_cap"] = cards["levels_below_cap"] == 0

rarity_order = ["common", "rare", "epic", "legendary", "champion"]

rarity_summary = cards.groupby("rarity").agg(card_count=("id", "size"), mean_levels_below_cap=("levels_below_cap", "mean"), cards_at_reported_cap=("at_reported_cap", "sum")).reindex(rarity_order)

rarity_summary.round(2)
Out[7]:
card_count mean_levels_below_cap cards_at_reported_cap
rarity
common 29 7.03 0
rare 30 9.33 0
epic 33 7.00 0
legendary 21 5.95 0
champion 6 4.33 0
In [8]:
cards.sort_values(["levels_below_cap", "name"])[["name","rarity", "level", "maxLevel", "levels_below_cap"]].head(10)
Out[8]:
name rarity level maxLevel levels_below_cap
32 Mega Knight legendary 5 8 3
113 Archer Queen champion 2 6 4
51 Arrows common 12 16 4
111 Golden Knight champion 2 6 4
116 Little Prince champion 2 6 4
94 Royal Delivery common 12 16 4
109 Skeleton King champion 2 6 4
58 Skeletons common 12 16 4
56 Witch epic 7 11 4
31 Bomber common 11 16 5
In [ ]:
ax = rarity_summary["mean_levels_below_cap"].plot.bar(figsize=(9, 4.5), color="#416B5B", rot=0,)

#Everything below is solely formatting the bar graph

ax.set(title="Card level gaps by rarity — API account snapshot", xlabel="Rarity", ylabel="Mean API level steps below reported cap",)

ax.set_xticklabels([f"{rarity.title()}\n"f"(n={int(rarity_summary.loc[rarity, 'card_count'])})" for rarity in rarity_summary.index])

ax.set_ylim(0, rarity_summary["mean_levels_below_cap"].max() * 1.15)

ax.bar_label(ax.containers[0], fmt="%.2f", padding=3)

plt.tight_layout()
plt.show()
No description has been provided for this image

Champions have the smallest average gap to their API-reported maximum level (4.33 steps), while rare cards have the largest (9.33 steps). However, rarities start at different in-game levels, with champions unlocking at level 11 and commons at level 1.

This chart measures remaining level steps. It does not establish which rarity has had the most upgrades since unlocking or received the greatest investments.

In [ ]:
elixir_cards = cards.dropna(subset=["elixirCost"]).copy()

elixir_summary = elixir_cards.groupby("elixirCost").agg(card_count=("id", "size"), mean_levels_below_cap=("levels_below_cap", "mean"))

ax = elixir_summary["mean_levels_below_cap"].plot.bar(figsize=(9, 4.5), color="#54738D", rot=0,)

#Same formatting from above graph

ax.set(title="Card level gaps by elixir cost — API account snapshot", xlabel="Reported elixir cost", ylabel="Mean API level steps below reported cap",)

ax.set_xticklabels([f"{cost:g}\n"f"(n={int(elixir_summary.loc[cost, 'card_count'])})" for cost in elixir_summary.index])

ax.set_ylim(0, elixir_summary["mean_levels_below_cap"].max() * 1.15)

ax.bar_label(ax.containers[0], fmt="%.2f", padding=3)

plt.tight_layout()
plt.show()
No description has been provided for this image
In [11]:
print("Cards included in the elixir chart:", len(elixir_cards))

elixir_summary.round(2)
Cards included in the elixir chart: 118
Out[11]:
card_count mean_levels_below_cap
elixirCost
1.0 5 7.20
2.0 14 7.00
3.0 27 6.74
4.0 33 7.24
5.0 20 7.70
6.0 12 7.75
7.0 5 6.80
8.0 1 10.00
9.0 1 13.00

The chart includes 118 cards with reported elixir costs. Mirror is excluded from this chart because its elixir cost is missing.

For elixir costs 1–7, average gaps range from 6.74 to 7.75 level steps. The eight- and nine-elixir categories have larger gaps of 10 and 13 steps, but each contains only one card.

These comparisons describe this account’s collection. Group sizes and rarity composition differ, and rarities have different starting levels. The chart does not establish how frequently these cards are used or how much has been invested in upgrading them.

Account performance¶

In [ ]:
player = account.iloc[0]

wins = int(player["wins"])
battles = int(player["battleCount"])
three_crown_wins = int(player["threeCrownWins"])

#Calculate win rate, avoiding division by zero when there are no battles
win_rate = wins / battles if battles else None

#Same thing for calculating three crown wins
three_crown_share = (
    three_crown_wins / wins if wins else None
)

account_summary = pd.Series(
    {
        #Format the player's stats into a thousands number with a comma
        "Trophies": f"{int(player['trophies']):,}",
        "Reported battles": f"{battles:,}",
        "Wins": f"{wins:,}",
        "Losses": f"{int(player['losses']):,}",
        "Win rate (wins / reported battles)": (
            f"{win_rate:.2%}"
            if win_rate is not None else "N/A"
        ),
        "Three-crown wins": f"{three_crown_wins:,}",
        "Three-crown share of wins": (
            f"{three_crown_share:.2%}"
            if three_crown_share is not None else "N/A"
        ),
        "Total donations": (
            f"{int(player['totalDonations']):,}"
        ),
        "Favorite card": (
            player["currentFavouriteCard"]["name"]
        ),
    }).to_frame(name="Value")

account_summary
Out[ ]:
Value
Trophies 7,283
Reported battles 1,113
Wins 655
Losses 458
Win rate (wins / reported battles) 58.85%
Three-crown wins 304
Three-crown share of wins 46.41%
Total donations 1,468
Favorite card Mega Knight

Findings and limitations¶

The API response contains 119 card records with no duplicate card IDs. None of the collected cards are at their API-reported maximum level. Mirror has no reported elixir cost, so the elixir-cost chart includes the other 118 cards.

The account has 7,283 trophies and 655 wins across 1,113 reported battles, giving a win rate of 58.85%. Of those wins, 304 were three-crown wins, representing 46.41% of wins.

The collection charts compare remaining level steps across rarity and elixir-cost groups. Different starting levels, unequal group sizes, and differences in rarity composition affect these comparisons. Level gaps do not measure upgrade costs or resources invested.

These results describe one account at the time of the API request.