What is League of Legends?

League of Legends is a 2009 MOBA (multiplayer online battle arena) video game made by Riot Games. It is one of the most popular video games, having 3.5 million daily active players. In the game, two teams of five players battle in player-versus-player combat, each team occupying and defending their half of the map. Each of the ten players controls a character, known as a “champion,” with unique abilities and differing play styles.

Which champion to pick?

As of June 9, 2022 there are currently 160 released champions. Such a wide selection can confuse newcomers as they will often not know what to play. The most basic champion statistics will be acquired and analyzed in the following sections. Every Tuesday, 16 out of the 160 total champions are chosen to be free-to-play in unranked games for that week.

How to acquire champion data?

In order to gather required information, League of Legends API is used. 

def get_data(url):
   response = requests.get(url)
   if response.status_code == 200:
       print("Successfully fetched the data")
       return response.json()
       print(f"Something went wrong!")

request_url = f'https://euw1.api.riotgames.com/lol/platform/v3/champion-rotations?api_key={API_KEY}'
free_champions = get_data(request_url)

By running the given python script, a user gets the following response:

    "freeChampionIds": [
    "freeChampionIdsForNewPlayers": [
    "maxNewPlayerLevel": 10

To keep things simple, we take into account 16 mentioned free-to-play champions. Since the given API call gives us 16 numbers instead of champion names, it is necessary to resolve such numbers in order to understand which champion it is.
We can fetch valuable data for all 160 champions by visiting League of Legends Data Dragon.

data_dragon_url = "http://ddragon.leagueoflegends.com/cdn/12.11.1/data/en_US/champion.json"
data_dragon = get_data(data_dragon_url)

freeChampionIdsgives us champion unique keys. Each champion has their unique key. An example of a champion from the list is provided below:

            "version": "12.11.1",
            "id": "Ivern",
            "key": "427",
            "name": "Ivern",
            "title": "the Green Father",
            "blurb": "Ivern Bramblefoot, known to many as the Green Father, is a peculiar half man, half tree who roams Runeterra's forests, cultivating life everywhere he goes. He knows the secrets of the natural world, and holds deep friendships with all things that grow...",
                "attack": 3,
                "defense": 5,
                "magic": 7,
                "difficulty": 7
                "full": "Ivern.png",
                "sprite": "champion1.png",
                "group": "champion",
                "x": 192,
                "y": 48,
                "w": 48,
                "h": 48
            "partype": "Mana",
                "hp": 655,
                "hpperlevel": 99,
                "mp": 450,
                "mpperlevel": 60,
                "movespeed": 330,
                "armor": 27,
                "armorperlevel": 4.7,
                "spellblock": 32,
                "spellblockperlevel": 2.05,
                "attackrange": 475,
                "hpregen": 7,
                "hpregenperlevel": 0.85,
                "mpregen": 6,
                "mpregenperlevel": 0.75,
                "crit": 0,
                "critperlevel": 0,
                "attackdamage": 50,
                "attackdamageperlevel": 3,
                "attackspeedperlevel": 3.4,
                "attackspeed": 0.644

In order to be able to resolve coded champions, we will collect certain information about every champion in the game and create an empty free_champions_resolved DataFrame where we will place our free champions.

champions = pd.DataFrame(columns = ['Image', 'Name', 'Key', 'Health', 'Attack'])
free_champions_resolved = champions.copy()

for champion in data_dragon['data']:

   champion_name = data_dragon['data'][champion]['name']
   champion_id = data_dragon['data'][champion]['id']

   champion_image = f'<img style = "display: block; margin-left: auto; margin-right: auto;"src = "http://ddragon.leagueoflegends.com/cdn/12.11.1/img/champion/{champion_id}.png "alt = ""width = "81"height = "81"/>'

   champion_key = int(data_dragon['data'][champion]['key'])
   champion_hp = int (data_dragon['data'][champion]['stats']['hp'])
   champion_attack= int(data_dragon['data'][champion]['stats']['attackdamage'])

   champions.loc[len(champions), champions.columns] = champion_image, champion_name, champion_key, champion_hp, champion_attack

To place wanted information in the empty DataFrame we run the following snippet:

for free_champion_id in free_champions['freeChampionIds']:

   temp_champion = champions.loc[champions['Key'] == free_champion_id]

   temp_champion_image = temp_champion.values[0][0]
   temp_champion_name = temp_champion.values[0][1]
   temp_champion_key = temp_champion.values[0][2]
   temp_champion_hp = temp_champion.values[0][3]
   temp_champion_attack = temp_champion.values[0][4]

   free_champions_resolved.loc[len(free_champions_resolved), free_champions_resolved.columns] = temp_champion_image, temp_champion_name, temp_champion_key, temp_champion_hp, temp_champion_attack


Now, we sort the champions by Attack and Health attributes:

free_champions_resolved = free_champions_resolved.sort_values(['Attack', 'Health'], ascending=[False, False])

For simplicity, we will take into account the top 5 champions:

free_champions_resolved = free_champions_resolved.head(5)

By running these scripts, we have formed our DataFrame:

League of Legends dataframe

The image column is the HTML code for a champion image which will be useful in the next section.

How to display data?

It is up to the user how to style the generated table. For text purposes, HTML code is generated using Beautiful Soup.

Our table that presents the top 5 free-to-play champions by Attack and Health attributes can look something like this:

 table that presents the top 5 free-to-play champions by Attack and Health attributes

“The Simplest League of Legends Champion Analysis” Tech Bite was brought to you by Omar Čelik, Junior Data Analyst at Atlantbh.

Tech Bites are tips, tricks, snippets or explanations about various programming technologies and paradigms, which can help engineers with their everyday job.

Software DevelopmentTech Bites
February 23, 2024

Background Jobs in Elixir – Oban

When and why do we need background jobs? Nowadays, background job processing is indispensable in the world of web development. The need for background jobs stems from the fact that synchronous execution of time-consuming and resource-intensive tasks would heavily impact an application's  performance and user experience.  Even though Elixir is…
QA/Test AutomationTech Bites
December 22, 2023

Selenium Grid 4 with Docker

Introduction When talking about automation testing, one of the first things that comes to mind is Selenium. Selenium is a free, open-source automated testing framework used to validate web applications across different browsers and platforms. It is not just a single tool but a suite of software. Every component of…
Software DevelopmentTech Bites
December 22, 2023

In-memory Caching using Redis

The importance of computer memory utilization The CPU and memory are the main components of any computer system. Computer memory stores data and program instructions, temporarily or permanently, that the CPU processes. In CPU-intensive applications with large amounts of data being processed, memory usually becomes the bottleneck, resulting in a…

Leave a Reply