Statement of Completion#7853759b
Data Wrangling with Pandas
medium
Exploring and Analysing Superhero Attributes using Pandas
Resolution
Activities
In [1]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
In [2]:
import warnings
warnings.filterwarnings('ignore')
In [3]:
df = pd.read_csv('superhero_data.csv')
1. Rename Columns¶
In [4]:
# Enter your code here
df.rename(columns={'type_race': 'race_type', 'has_immortality': 'is_immortal'}, inplace=True)
2. Convert Ability Columns to Descriptive Labels¶
In [5]:
# Enter your code here
bin_col = ['has_shapeshifting', 'has_telepathy', 'has_regeneration', 'is_immortal', 'has_teleportation']
df[bin_col] = df[bin_col].replace({0: 'No', 1: 'Yes'})
3. Select the First 10 Rows of the DataFrame¶
In [6]:
# Enter your code here
first_ten_rows = df.head(10)
print(first_ten_rows)
name real_name overall_score \ 0 3-D Man Delroy Garrett, Jr. 6 1 514A (Gotham) Bruce Wayne 10 2 A-Bomb Richard Milhouse Jones 20 3 Aa Aa 12 4 Aaron Cash Aaron Cash 5 5 Aayla Secura Aayla Secura 8 6 Abe Sapien Abraham Sapien 10 7 Abin Sur NaN 9 8 Abomination Emil Blonsky 22 9 Abra Kadabra (CW) Unknown 13 intelligence_score strength_score speed_score durability_score \ 0 85 30 60 60 1 100 20 30 50 2 80 100 80 100 3 80 50 55 45 4 80 10 25 40 5 90 40 45 55 6 95 30 35 65 7 75 90 55 65 8 85 100 80 90 9 100 10 20 30 power_score superpowers \ 0 40 ['Super Speed', 'Super Strength'] 1 35 ['Durability', 'Reflexes', 'Super Strength'] 2 100 ['Accelerated Healing', 'Agility', 'Berserk Mo... 3 100 ['Energy Absorption', 'Energy Armor', 'Energy ... 4 30 ['Weapon-based Powers', 'Weapons Master'] 5 55 ['Accelerated Healing', 'Agility', 'Astral Pro... 6 100 ['Accelerated Healing', 'Agility', 'Cold Resis... 7 100 ['Lantern Power Ring'] 8 100 ['Accelerated Healing', 'Adaptation', 'Agility... 9 100 ['Dimensional Travel', 'Illusions', 'Intellige... place_of_birth ... teams \ 0 NaN ... ['Annihilators', 'Asgardians', 'Avengers', 'Ne... 1 NaN ... [] 2 Scarsdale, Arizona ... ['Teen Brigade', 'Ultimate Fantastic Four', 'U... 3 Stoneworld ... ['Blue Lantern Corps', 'Green Lantern Corps', ... 4 Gotham City ... [] 5 NaN ... ['Jedi Order'] 6 NaN ... ['Bureau for Paranormal Research and Defense'] 7 Ungara ... ['Legion of Super-Heroes', 'Green Lantern Corps'] 8 Zagreb, Yugoslavia ... ['Annihilators', 'Wrecking Crew', 'Masters of ... 9 64th Century ... [] gender race_type height skin_color has_shapeshifting \ 0 Male Human - NaN No 1 NaN NaN - NaN No 2 Male Human 6'8 • 203 cm NaN Yes 3 Male Human - NaN No 4 Male Human - NaN No 5 Female Twi'lek - NaN No 6 Male Icthyo Sapien 6'3 • 191 cm Blue No 7 Male Ungaran 6'1 • 185 cm Red No 8 Male Human / Radiation 6'8 • 203 cm NaN No 9 Male Human 6'0" • 183 cm NaN No has_telepathy has_regeneration is_immortal has_teleportation 0 No No No No 1 No No No No 2 No Yes No No 3 No No No No 4 No No No No 5 No No No No 6 Yes No Yes No 7 No No No No 8 No Yes No No 9 No No No Yes [10 rows x 25 columns]
4. Drop Columns with High Missing Values¶
In [7]:
# Enter your code here
threshold = 0.7 * len(df)
df.dropna(thresh=threshold, axis=1, inplace=True)
5. Remove Rows Containing NaN Values and Reset the Index¶
In [8]:
# Enter your code here
df.dropna(inplace=True)
df.reset_index(drop=True, inplace=True)
6. Convert Height Strings to Numeric Values¶
In [10]:
# Enter your code here
df['height'] = df['height'].str.split('•').str[1].str.strip(' cm')
df['height'] = pd.to_numeric(df['height'],errors='coerce',downcast='integer')
df['height']
Out[10]:
0 203.0 1 191.0 2 203.0 3 183.0 4 198.0 ... 563 188.0 564 183.0 565 168.0 566 188.0 567 160.0 Name: height, Length: 568, dtype: float64
7. Filter and Store Human Race Superheroes¶
In [12]:
# Enter your code here
df_human_race = df[df['race_type'] == 'Human']
print(df_human_race)
name real_name overall_score \ 0 A-Bomb Richard Milhouse Jones 20 3 Abra Kadabra (CW) Unknown 13 4 Abra Kadabra Abhararakadhararbarakh 29 5 Absorbing Man (MCU) Carl Creel 8 6 Absorbing Man Carl Creel 13 .. ... ... ... 553 Witch King Witch-King of Angmar 12 554 Witchblade Sara Pezzini 10 562 Yellowjacket II Rita DeMara 4 563 YellowJacket (MCU) Darren Cross 10 564 Yellowjacket Hank Pym 8 intelligence_score strength_score speed_score durability_score \ 0 80 100 80 100 3 100 10 20 30 4 100 10 25 70 5 75 15 30 40 6 70 80 25 100 .. ... ... ... ... 553 65 20 65 90 554 85 40 40 90 562 75 10 35 30 563 95 35 60 70 564 95 10 10 30 power_score superpowers \ 0 100 ['Accelerated Healing', 'Agility', 'Berserk Mo... 3 100 ['Dimensional Travel', 'Illusions', 'Intellige... 4 100 ['Animation', 'Astral Projection', 'Dimensiona... 5 100 ['Agility', 'Camouflage', 'Cold Resistance', '... 6 100 ['Absorption', 'Cold Resistance', 'Density Con... .. ... ... 553 100 ['Absorption', 'Energy Blasts', 'Fire Control'... 554 100 ['Accelerated Healing', 'Agility', 'Energy Bla... 562 30 ['Energy Blasts', 'Flight', 'Size Changing'] 563 70 ['Density Control', 'Durability', 'Energy Beam... 564 10 ['Animal Oriented Powers', 'Size Changing'] first_appearance ... \ 0 Hulk Vol 2 #2 (April, 2008) (as A-Bomb) ... 3 The Flash Season 3: Episode 18 ... 4 The Flash #128 - The Case of the Real-Gone Flash ... 5 Agents of S.H.I.E.L.D. Season 2: Episode 1 ... 6 Journey Into Mystery (1952) Issue #114 ... .. ... ... 553 Lord of the Rings #1 ... 554 Witchblade Issue 1 ... 562 Avengers #264 ... 563 Ant-Man (2015) ... 564 (as Pym) TALES TO ASTONISH #27, (as Ant-Man) T... ... occupation \ 0 Musician, adventurer, author; formerly talk sh... 3 Time-Travelling Criminal 4 Magician, Sorcerer 5 Government Agent, Bodyguard 6 Professional criminal; former professional boxer .. ... 553 King of Angmar, Lord of Minas Morgul, Lord of ... 554 Detective 562 Adventurer; former criminal, electronics engin... 563 CEO of Cross Technological Enterprises 564 Adventurer, Biochemist, former manager of Aven... teams gender race_type \ 0 ['Teen Brigade', 'Ultimate Fantastic Four', 'U... Male Human 3 [] Male Human 4 ['Teen Titans', 'Extreme Justice', 'Rogues', '... Male Human 5 [] Male Human 6 ['Marvel Knights', 'Masters of Evil', 'Nationa... Male Human .. ... ... ... 553 [] Male Human 554 [] Female Human 562 ['Masters of Evil'] Female Human 563 [] Male Human 564 ['Illuminati'] Male Human height has_shapeshifting has_telepathy has_regeneration is_immortal \ 0 203.0 Yes No Yes No 3 183.0 No No No No 4 198.0 No No No Yes 5 193.0 No No No No 6 193.0 Yes No Yes Yes .. ... ... ... ... ... 553 NaN No No No Yes 554 175.0 Yes No No No 562 165.0 No No No No 563 188.0 No No No No 564 183.0 No No No No has_teleportation 0 No 3 Yes 4 No 5 No 6 No .. ... 553 No 554 No 562 No 563 No 564 No [325 rows x 22 columns]
8. Filter Superheroes by Alignment and Creator¶
In [14]:
# Enter your code here
marvel_good_alignment = df[(df['alignment'] == 'Good') & (df['creator'] == 'Marvel Comics')]
print(marvel_good_alignment)
name real_name overall_score \ 0 A-Bomb Richard Milhouse Jones 20 5 Absorbing Man (MCU) Carl Creel 8 9 Agent 13 (MCU) Sharon Carter 9 10 Agent Bob Bob 2 11 Agent Carter Carter 8 .. ... ... ... 561 X-23 Laura Kinney 8 562 Yellowjacket II Rita DeMara 4 564 Yellowjacket Hank Pym 8 565 Yo-yo (MCU) Elena Rodriguez 7 567 Yukio (FOX) Yukio 5 intelligence_score strength_score speed_score durability_score \ 0 80 100 80 100 5 75 15 30 40 9 95 20 70 50 10 60 10 15 5 11 95 10 15 20 .. ... ... ... ... 561 90 25 40 100 562 75 10 35 30 564 95 10 10 30 565 80 35 100 40 567 80 10 50 30 power_score superpowers \ 0 100 ['Accelerated Healing', 'Agility', 'Berserk Mo... 5 100 ['Agility', 'Camouflage', 'Cold Resistance', '... 9 45 ['Intelligence', 'Peak Human Condition', 'Weap... 10 5 ['Stealth'] 11 25 ['Agility', 'Hacking', 'Weapons Master'] .. ... ... 561 55 ['Accelerated Healing', 'Agility', 'Durability... 562 30 ['Energy Blasts', 'Flight', 'Size Changing'] 564 10 ['Animal Oriented Powers', 'Size Changing'] 565 60 ['Agility', 'Bullet Time', 'Endurance', 'Marks... 567 45 ['Agility', 'Dexterity', 'Endurance', 'Marksma... first_appearance ... \ 0 Hulk Vol 2 #2 (April, 2008) (as A-Bomb) ... 5 Agents of S.H.I.E.L.D. Season 2: Episode 1 ... 9 Agents of S.H.I.E.L.D ... 10 Cable & Deadpool #38 (May, 2007) ... 11 Tales of Suspense #75 (March, 1966) ... .. ... ... 561 NYX #3 ... 562 Avengers #264 ... 564 (as Pym) TALES TO ASTONISH #27, (as Ant-Man) T... ... 565 Agents of S.H.I.E.L.D. Season 3: Episode 11 ... 567 The Wolverine ... occupation \ 0 Musician, adventurer, author; formerly talk sh... 5 Government Agent, Bodyguard 9 S.H.I.E.L.D agent 10 Mercenary, janitor; former pirate, terrorist 11 Shield agent .. ... 561 Adventurer, Student, former; Assassin, Prostit... 562 Adventurer; former criminal, electronics engin... 564 Adventurer, Biochemist, former manager of Aven... 565 Museum Clerk, S.H.I.E.L.D. Agent 567 Bodyguard teams gender \ 0 ['Teen Brigade', 'Ultimate Fantastic Four', 'U... Male 5 [] Male 9 [] Female 10 ['Agency X', 'A.I.M.', 'HYDRA'] Male 11 [] Male .. ... ... 561 ["Apocalypse's Horsemen", 'New X-Men', 'X-Forc... Female 562 ['Masters of Evil'] Female 564 ['Illuminati'] Male 565 [] Female 567 [] Female race_type height has_shapeshifting has_telepathy has_regeneration \ 0 Human 203.0 Yes No Yes 5 Human 193.0 No No No 9 Human 168.0 No No No 10 Human 178.0 No No No 11 Human 0.0 No No No .. ... ... ... ... ... 561 Mutant / Clone 155.0 No No No 562 Human 165.0 No No No 564 Human 183.0 No No No 565 Inhuman 168.0 No No No 567 Mutant 160.0 No No No is_immortal has_teleportation 0 No No 5 No No 9 No No 10 No No 11 No No .. ... ... 561 No No 562 No No 564 No No 565 No No 567 No No [152 rows x 22 columns]
9. Sort by Overall Score and Intelligence¶
In [16]:
# Enter your code here
df_sorted = df.sort_values(by=['overall_score', 'intelligence_score'], ascending=[False, False])
print(df_sorted)
name real_name overall_score intelligence_score \ 192 Golden Ninja Lloyd Garmadon 226 100 509 The Keeper Norrin Radd 152 75 528 Unicron Unicron 146 100 155 Dormammu Dormammu 142 100 157 Dr Manhattan Jonathan Osterman 124 100 .. ... ... ... ... 364 Morty Smith Morty Smith 3 65 229 Honey Badger Gabrielle Kinney 3 50 10 Agent Bob Bob 2 60 29 Arnold Flass Arnold Flass 2 60 92 Captain Boomerang George Harkness 2 60 strength_score speed_score durability_score power_score \ 192 100 100 100 100 509 100 100 100 100 528 100 100 100 100 155 100 100 100 100 157 100 40 100 100 .. ... ... ... ... 364 10 25 40 70 229 35 75 65 70 10 10 15 5 5 29 10 20 10 20 92 15 40 40 40 superpowers \ 192 ['Acausality', 'Accelerated Healing', 'Age Man... 509 ['Accelerated Healing', 'Agility', 'Astral Pro... 528 ['Adaptation', 'Agility', 'Anti-Gravity', 'Bio... 155 ['Absorption', 'Astral Projection', 'Audio Con... 157 ['Accelerated Healing', 'Density Control', 'Du... .. ... 364 ['Energy Beams', 'Energy Blasts', 'Memory Mani... 229 ['Acrobatics', 'Agility', 'Durability', 'Enhan... 10 ['Stealth'] 29 ['Law Manipulation', 'Master Martial Artist', ... 92 ['Agility', 'Marksmanship', 'Reflexes', 'Stami... first_appearance ... \ 192 Rise of the Spinjitzu Master ... 509 Silver Surfer Annual #4 (July, 1991) ... 528 The Transformers: The Movie ... 155 Strange Tales #126 (1964) ... 157 Watchmen #1 (September, 1986) ... .. ... ... 364 Rick and Morty S01E01 ... 229 All-New Wolverine #2 ... 10 Cable & Deadpool #38 (May, 2007) ... 29 Batman #404 ... 92 The Flash #117 - Here Comes Captain Boomerang!... ... occupation \ 192 Ninja 509 Eon's Protector of the Universe; Spacefaring a... 528 God, Devourer of Worlds, God of Chaos 155 Despot, conqueror 157 Scientist .. ... 364 Student, Space Adventurer 229 Vigilante, adventurer 10 Mercenary, janitor; former pirate, terrorist 29 Soldier · Detective · Police Officer 92 Professional Criminal teams gender \ 192 [] Male 509 [] Male 528 [] Male 155 ['Gods', 'Demons', 'Titans'] Male 157 ['Watchmen', 'The Crimebusters'] Male .. ... ... 364 [] Male 229 [] Female 10 ['Agency X', 'A.I.M.', 'HYDRA'] Male 29 [] Male 92 ['Suicide Squad', 'Rogues', 'Living Assault We... Male race_type height has_shapeshifting has_telepathy has_regeneration \ 192 God / Eternal 168.0 Yes Yes No 509 Alien 193.0 Yes Yes Yes 528 God / Eternal NaN Yes Yes Yes 155 Cosmic Entity NaN Yes Yes Yes 157 Human / Cosmic NaN No No Yes .. ... ... ... ... ... 364 Human NaN No No No 229 Clone 137.0 No No Yes 10 Human 178.0 No No No 29 Human NaN No No No 92 Human 175.0 No No No is_immortal has_teleportation 192 No Yes 509 Yes Yes 528 Yes No 155 Yes Yes 157 Yes Yes .. ... ... 364 No Yes 229 No No 10 No No 29 No No 92 No No [568 rows x 22 columns]
10. Filter Superheroes with Specific Superpowers¶
In [18]:
# Enter your code here
df_superpowers = df[df['superpowers'].str.contains('Super Speed') & df['superpowers'].str.contains('Super Strength')]
print(df_superpowers)
name real_name overall_score \ 0 A-Bomb Richard Milhouse Jones 20 2 Abomination Emil Blonsky 22 7 Achilles Warkiller Achilles Warkiller 19 19 Angela Aldrif Odinsdottir 15 23 Aqualad Garth 7 .. ... ... ... 557 Wonder Girl Diana Prince 18 558 Wonder Woman (Kingdom Come) Diana Of Themyscira 23 559 Wonder Woman Diana Prince 17 560 World Breaker Hulk Bruce Banner 37 565 Yo-yo (MCU) Elena Rodriguez 7 intelligence_score strength_score speed_score durability_score \ 0 80 100 80 100 2 85 100 80 90 7 90 100 75 100 19 90 90 70 75 23 80 45 40 75 .. ... ... ... ... 557 95 100 75 100 558 95 100 80 100 559 95 100 80 100 560 85 100 85 100 565 80 35 100 40 power_score superpowers \ 0 100 ['Accelerated Healing', 'Agility', 'Berserk Mo... 2 100 ['Accelerated Healing', 'Adaptation', 'Agility... 7 100 ['Accelerated Healing', 'Agility', 'Durability... 19 100 ['Accelerated Healing', 'Agility', 'Durability... 23 90 ['Cryokinesis', 'Durability', 'Energy Beams', ... .. ... ... 557 100 ['Durability', 'Flight', 'Immortality', 'Invul... 558 100 ['Accelerated Healing', 'Durability', 'Empathy... 559 100 ['Accelerated Healing', 'Animal Oriented Power... 560 100 ['Accelerated Healing', 'Adaptation', 'Agility... 565 60 ['Agility', 'Bullet Time', 'Endurance', 'Marks... first_appearance ... \ 0 Hulk Vol 2 #2 (April, 2008) (as A-Bomb) ... 2 Tales to Astonish #90 ... 7 Wonder Woman Vol 3 #30 ... 19 Spawn #9 - Angela ... 23 Adventure Comics #269 (February, 1960) ... .. ... ... 557 Wonder Woman Vol 2 #105 ... 558 Kingdom Come #1 ... 559 All-Star Comics #8 (December, 1941) ... 560 World War Hulk Vol 1 #5 ... 565 Agents of S.H.I.E.L.D. Season 3: Episode 11 ... occupation \ 0 Musician, adventurer, author; formerly talk sh... 2 Ex-Spy 7 Adventurer, Warrior, King 19 Adventurer, hunter, mercenary; Queen of Hel, L... 23 Adventurer; Magician, former Sidekick .. ... 557 Student 558 Ambassador 559 Adventurer, Emissary to the world of Man, Prot... 560 Nuclear physicist, Agent of S.H.I.E.L.D. 565 Museum Clerk, S.H.I.E.L.D. Agent teams gender \ 0 ['Teen Brigade', 'Ultimate Fantastic Four', 'U... Male 2 ['Annihilators', 'Wrecking Crew', 'Masters of ... Male 7 [] Male 19 [] Female 23 ['Justice League Atlantis', 'Aquaman Family', ... Male .. ... ... 557 [] Female 558 [] Female 559 ['Superfriends', 'Justice League Elite', 'All-... Female 560 [] Male 565 [] Female race_type height has_shapeshifting has_telepathy \ 0 Human 203.0 Yes No 2 Human / Radiation 203.0 No No 7 God / Eternal 185.0 No No 19 God / Eternal 188.0 No No 23 Atlantean 178.0 No Yes .. ... ... ... ... 557 Demi-God 3.0 No No 558 Amazon NaN No No 559 Amazon 183.0 No Yes 560 Human / Radiation 274.0 Yes No 565 Inhuman 168.0 No No has_regeneration is_immortal has_teleportation 0 Yes No No 2 Yes No No 7 Yes No No 19 No Yes No 23 No No No .. ... ... ... 557 No Yes No 558 No Yes No 559 No No No 560 Yes Yes No 565 No No No [201 rows x 22 columns]
11. Group by Creator and Calculate Average Scores¶
In [20]:
# Enter your code here
average_scores_by_creator = df.groupby('creator')['overall_score'].mean().reset_index()
print(average_scores_by_creator)
creator overall_score 0 Capcom 26.500000 1 Cartoon Network 11.000000 2 DC Comics 12.553488 3 Dark Horse Comics 13.777778 4 Disney 7.000000 5 George Lucas 30.714286 6 George R. R. Martin 6.000000 7 Hasbro 55.000000 8 IDW Publishing 7.500000 9 Ian Fleming 8.000000 10 Icon Comics 3.000000 11 Image Comics 22.333333 12 J. K. Rowling 21.000000 13 J. R. R. Tolkien 12.000000 14 Lego 22.133333 15 Marvel Comics 13.830709 16 Matt Groening 8.000000 17 Mortal Kombat 75.000000 18 Nintendo 44.500000 19 Shueisha 22.538462 20 Sony Pictures 6.000000 21 South Park 3.000000 22 Star Trek 6.000000 23 Ubisoft 7.750000 24 Universal Studios 8.000000 25 Wildstorm 6.000000
12. Identify the Creator Whose Characters Have the Highest Average Overall Score?¶
In [22]:
# Enter your code here
top_creat = average_scores_by_creator.sort_values(by='overall_score', ascending=False).iloc[0]
print(top_creat)
creator Mortal Kombat overall_score 75.0 Name: 17, dtype: object
13. Analyze Race Based on Intelligence¶
In [23]:
# Enter your code here
race_intelligence = df.groupby('race_type')['intelligence_score'].mean().reset_index()
print(race_intelligence)
race_type intelligence_score 0 Alien 81.176471 1 Amazon 95.000000 2 Android 90.000000 3 Animal 84.166667 4 Asgardian 78.571429 5 Atlantean 87.857143 6 Clone 72.500000 7 Cosmic Entity 91.250000 8 Cyborg 87.857143 9 Czarnian 95.000000 10 Dathomirian Zabrak 85.000000 11 Daxamite 90.000000 12 Demi-God 77.500000 13 Demon 76.000000 14 Elder 72.500000 15 Energy 85.000000 16 Eternal 87.500000 17 God / Eternal 87.941176 18 Gorilla 95.000000 19 Human 86.969231 20 Human / Altered 93.000000 21 Human / Cosmic 100.000000 22 Human / Radiation 84.062500 23 Human-Inhuman 100.000000 24 Human-Spartoi 85.000000 25 Icthyo Sapien 95.000000 26 Inhuman 81.250000 27 Kree 85.000000 28 Kryptonian 92.142857 29 Lego 70.000000 30 Leprechaun 80.000000 31 Metahuman 85.200000 32 Mutant 82.033898 33 Mutant / Clone 90.000000 34 New God 100.000000 35 Planet 100.000000 36 Robot 90.000000 37 Saiyan 81.000000 38 Strontian 75.000000 39 Symbiote 82.000000 40 Tamaranean 85.000000 41 Titanian 88.333333 42 Vampire 85.000000 43 Zen-Whoberian 90.000000
14. Among the following what is the most intelligent superhero race?¶
In [25]:
# Enter your code here
most_intelligent_race = race_intelligence.sort_values(by='intelligence_score', ascending=False).iloc[0]
print(most_intelligent_race)
race_type New God intelligence_score 100.0 Name: 34, dtype: object
15. Discretize Overall Scores¶
In [26]:
# Enter your code here
def categorize_score(score):
if 0 <= score <= 50:
return 'Very Low'
elif 51 <= score <= 100:
return 'Low'
elif 101 <= score <= 150:
return 'Moderate'
elif 151 <= score <= 200:
return 'High'
elif 201 <= score <= 250:
return 'Very High'
else:
return 'Unknown'
df['score_category'] = df['overall_score'].apply(categorize_score)
df
Out[26]:
name | real_name | overall_score | intelligence_score | strength_score | speed_score | durability_score | power_score | superpowers | first_appearance | ... | teams | gender | race_type | height | has_shapeshifting | has_telepathy | has_regeneration | is_immortal | has_teleportation | score_category | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | A-Bomb | Richard Milhouse Jones | 20 | 80 | 100 | 80 | 100 | 100 | ['Accelerated Healing', 'Agility', 'Berserk Mo... | Hulk Vol 2 #2 (April, 2008) (as A-Bomb) | ... | ['Teen Brigade', 'Ultimate Fantastic Four', 'U... | Male | Human | 203.0 | Yes | No | Yes | No | No | Very Low |
1 | Abe Sapien | Abraham Sapien | 10 | 95 | 30 | 35 | 65 | 100 | ['Accelerated Healing', 'Agility', 'Cold Resis... | Hellboy: Seed of Destruction | ... | ['Bureau for Paranormal Research and Defense'] | Male | Icthyo Sapien | 191.0 | No | Yes | No | Yes | No | Very Low |
2 | Abomination | Emil Blonsky | 22 | 85 | 100 | 80 | 90 | 100 | ['Accelerated Healing', 'Adaptation', 'Agility... | Tales to Astonish #90 | ... | ['Annihilators', 'Wrecking Crew', 'Masters of ... | Male | Human / Radiation | 203.0 | No | No | Yes | No | No | Very Low |
3 | Abra Kadabra (CW) | Unknown | 13 | 100 | 10 | 20 | 30 | 100 | ['Dimensional Travel', 'Illusions', 'Intellige... | The Flash Season 3: Episode 18 | ... | [] | Male | Human | 183.0 | No | No | No | No | Yes | Very Low |
4 | Abra Kadabra | Abhararakadhararbarakh | 29 | 100 | 10 | 25 | 70 | 100 | ['Animation', 'Astral Projection', 'Dimensiona... | The Flash #128 - The Case of the Real-Gone Flash | ... | ['Teen Titans', 'Extreme Justice', 'Rogues', '... | Male | Human | 198.0 | No | No | No | Yes | No | Very Low |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
563 | YellowJacket (MCU) | Darren Cross | 10 | 95 | 35 | 60 | 70 | 70 | ['Density Control', 'Durability', 'Energy Beam... | Ant-Man (2015) | ... | [] | Male | Human | 188.0 | No | No | No | No | No | Very Low |
564 | Yellowjacket | Hank Pym | 8 | 95 | 10 | 10 | 30 | 10 | ['Animal Oriented Powers', 'Size Changing'] | (as Pym) TALES TO ASTONISH #27, (as Ant-Man) T... | ... | ['Illuminati'] | Male | Human | 183.0 | No | No | No | No | No | Very Low |
565 | Yo-yo (MCU) | Elena Rodriguez | 7 | 80 | 35 | 100 | 40 | 60 | ['Agility', 'Bullet Time', 'Endurance', 'Marks... | Agents of S.H.I.E.L.D. Season 3: Episode 11 | ... | [] | Female | Inhuman | 168.0 | No | No | No | No | No | Very Low |
566 | Yondu | Yondu Udonta | 5 | 75 | 15 | 30 | 50 | 60 | ['Agility', 'Durability', 'Intelligence', 'Mar... | Marvel Super-Heroes #18 - Origin of the Guardi... | ... | ['Marvel Knights', 'Guardians of the Galaxy', ... | Male | Alien | 188.0 | No | No | No | No | No | Very Low |
567 | Yukio (FOX) | Yukio | 5 | 80 | 10 | 50 | 30 | 45 | ['Agility', 'Dexterity', 'Endurance', 'Marksma... | The Wolverine | ... | [] | Female | Mutant | 160.0 | No | No | No | No | No | Very Low |
568 rows × 23 columns
16. Create a Power Index¶
In [28]:
# Enter your code here
df['power_index'] = df.apply(lambda row: row['intelligence_score'] + row['speed_score'] + row['durability_score'], axis=1)
df
Out[28]:
name | real_name | overall_score | intelligence_score | strength_score | speed_score | durability_score | power_score | superpowers | first_appearance | ... | gender | race_type | height | has_shapeshifting | has_telepathy | has_regeneration | is_immortal | has_teleportation | score_category | power_index | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | A-Bomb | Richard Milhouse Jones | 20 | 80 | 100 | 80 | 100 | 100 | ['Accelerated Healing', 'Agility', 'Berserk Mo... | Hulk Vol 2 #2 (April, 2008) (as A-Bomb) | ... | Male | Human | 203.0 | Yes | No | Yes | No | No | Very Low | 260 |
1 | Abe Sapien | Abraham Sapien | 10 | 95 | 30 | 35 | 65 | 100 | ['Accelerated Healing', 'Agility', 'Cold Resis... | Hellboy: Seed of Destruction | ... | Male | Icthyo Sapien | 191.0 | No | Yes | No | Yes | No | Very Low | 195 |
2 | Abomination | Emil Blonsky | 22 | 85 | 100 | 80 | 90 | 100 | ['Accelerated Healing', 'Adaptation', 'Agility... | Tales to Astonish #90 | ... | Male | Human / Radiation | 203.0 | No | No | Yes | No | No | Very Low | 255 |
3 | Abra Kadabra (CW) | Unknown | 13 | 100 | 10 | 20 | 30 | 100 | ['Dimensional Travel', 'Illusions', 'Intellige... | The Flash Season 3: Episode 18 | ... | Male | Human | 183.0 | No | No | No | No | Yes | Very Low | 150 |
4 | Abra Kadabra | Abhararakadhararbarakh | 29 | 100 | 10 | 25 | 70 | 100 | ['Animation', 'Astral Projection', 'Dimensiona... | The Flash #128 - The Case of the Real-Gone Flash | ... | Male | Human | 198.0 | No | No | No | Yes | No | Very Low | 195 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
563 | YellowJacket (MCU) | Darren Cross | 10 | 95 | 35 | 60 | 70 | 70 | ['Density Control', 'Durability', 'Energy Beam... | Ant-Man (2015) | ... | Male | Human | 188.0 | No | No | No | No | No | Very Low | 225 |
564 | Yellowjacket | Hank Pym | 8 | 95 | 10 | 10 | 30 | 10 | ['Animal Oriented Powers', 'Size Changing'] | (as Pym) TALES TO ASTONISH #27, (as Ant-Man) T... | ... | Male | Human | 183.0 | No | No | No | No | No | Very Low | 135 |
565 | Yo-yo (MCU) | Elena Rodriguez | 7 | 80 | 35 | 100 | 40 | 60 | ['Agility', 'Bullet Time', 'Endurance', 'Marks... | Agents of S.H.I.E.L.D. Season 3: Episode 11 | ... | Female | Inhuman | 168.0 | No | No | No | No | No | Very Low | 220 |
566 | Yondu | Yondu Udonta | 5 | 75 | 15 | 30 | 50 | 60 | ['Agility', 'Durability', 'Intelligence', 'Mar... | Marvel Super-Heroes #18 - Origin of the Guardi... | ... | Male | Alien | 188.0 | No | No | No | No | No | Very Low | 155 |
567 | Yukio (FOX) | Yukio | 5 | 80 | 10 | 50 | 30 | 45 | ['Agility', 'Dexterity', 'Endurance', 'Marksma... | The Wolverine | ... | Female | Mutant | 160.0 | No | No | No | No | No | Very Low | 160 |
568 rows × 24 columns
17. Count the Number of Superpowers¶
In [30]:
# Enter your code here
df['num_superpowers'] = df['superpowers'].apply(lambda x: len(x.split(',')) if pd.notnull(x) else 0)
df
Out[30]:
name | real_name | overall_score | intelligence_score | strength_score | speed_score | durability_score | power_score | superpowers | first_appearance | ... | race_type | height | has_shapeshifting | has_telepathy | has_regeneration | is_immortal | has_teleportation | score_category | power_index | num_superpowers | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | A-Bomb | Richard Milhouse Jones | 20 | 80 | 100 | 80 | 100 | 100 | ['Accelerated Healing', 'Agility', 'Berserk Mo... | Hulk Vol 2 #2 (April, 2008) (as A-Bomb) | ... | Human | 203.0 | Yes | No | Yes | No | No | Very Low | 260 | 41 |
1 | Abe Sapien | Abraham Sapien | 10 | 95 | 30 | 35 | 65 | 100 | ['Accelerated Healing', 'Agility', 'Cold Resis... | Hellboy: Seed of Destruction | ... | Icthyo Sapien | 191.0 | No | Yes | No | Yes | No | Very Low | 195 | 16 |
2 | Abomination | Emil Blonsky | 22 | 85 | 100 | 80 | 90 | 100 | ['Accelerated Healing', 'Adaptation', 'Agility... | Tales to Astonish #90 | ... | Human / Radiation | 203.0 | No | No | Yes | No | No | Very Low | 255 | 30 |
3 | Abra Kadabra (CW) | Unknown | 13 | 100 | 10 | 20 | 30 | 100 | ['Dimensional Travel', 'Illusions', 'Intellige... | The Flash Season 3: Episode 18 | ... | Human | 183.0 | No | No | No | No | Yes | Very Low | 150 | 7 |
4 | Abra Kadabra | Abhararakadhararbarakh | 29 | 100 | 10 | 25 | 70 | 100 | ['Animation', 'Astral Projection', 'Dimensiona... | The Flash #128 - The Case of the Real-Gone Flash | ... | Human | 198.0 | No | No | No | Yes | No | Very Low | 195 | 18 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
563 | YellowJacket (MCU) | Darren Cross | 10 | 95 | 35 | 60 | 70 | 70 | ['Density Control', 'Durability', 'Energy Beam... | Ant-Man (2015) | ... | Human | 188.0 | No | No | No | No | No | Very Low | 225 | 12 |
564 | Yellowjacket | Hank Pym | 8 | 95 | 10 | 10 | 30 | 10 | ['Animal Oriented Powers', 'Size Changing'] | (as Pym) TALES TO ASTONISH #27, (as Ant-Man) T... | ... | Human | 183.0 | No | No | No | No | No | Very Low | 135 | 2 |
565 | Yo-yo (MCU) | Elena Rodriguez | 7 | 80 | 35 | 100 | 40 | 60 | ['Agility', 'Bullet Time', 'Endurance', 'Marks... | Agents of S.H.I.E.L.D. Season 3: Episode 11 | ... | Inhuman | 168.0 | No | No | No | No | No | Very Low | 220 | 10 |
566 | Yondu | Yondu Udonta | 5 | 75 | 15 | 30 | 50 | 60 | ['Agility', 'Durability', 'Intelligence', 'Mar... | Marvel Super-Heroes #18 - Origin of the Guardi... | ... | Alien | 188.0 | No | No | No | No | No | Very Low | 155 | 10 |
567 | Yukio (FOX) | Yukio | 5 | 80 | 10 | 50 | 30 | 45 | ['Agility', 'Dexterity', 'Endurance', 'Marksma... | The Wolverine | ... | Mutant | 160.0 | No | No | No | No | No | Very Low | 160 | 10 |
568 rows × 25 columns
18. Visualize Overall Score Distribution¶
In [38]:
fig, ax = plt.subplots(figsize=(8, 8))
overall_score_histogram = df['overall_score'].plot(kind='hist', bins=10, ax=ax) # fill the code in the placeholder
ax.set_title('Distribution of Overall Score')
ax.set_xlabel('Overall Score')
ax.set_ylabel('Frequency')
Out[38]:
Text(0, 0.5, 'Frequency')
19. Create a Correlation Matrix¶
In [41]:
# Enter your code here
score_cols = ['intelligence_score', 'speed_score', 'durability_score', 'overall_score']
correlation_matrix = df[score_cols].corr()
print(correlation_matrix)
intelligence_score speed_score durability_score \ intelligence_score 1.000000 -0.084295 -0.081409 speed_score -0.084295 1.000000 0.623535 durability_score -0.081409 0.623535 1.000000 overall_score 0.155732 0.424233 0.397558 overall_score intelligence_score 0.155732 speed_score 0.424233 durability_score 0.397558 overall_score 1.000000
20. Which two following columns have the highest correlation score?¶
In [ ]:
# Enter your code here
21. Scatter Plot of Height vs Power Score¶
In [43]:
fig, ax = plt.subplots(figsize=(8, 8))
height_vs_power_plot = df.plot(kind='scatter', x='height', y='power_score', title='Height vs Power Score', xlabel='Height', ax=ax) # fill the code
22. Analyze Superpowers Across Genders¶
In [45]:
# Enter your code here
gender_superpowers = df.groupby('gender')['num_superpowers'].mean().reset_index()
print(gender_superpowers)
gender num_superpowers 0 Female 12.208054 1 Male 16.904535
23. Analyze Alignment Distribution¶
In [49]:
fig, ax = plt.subplots(figsize=(8, 8))
alignment_counts = df['alignment'].value_counts() # fill the code
alignment_pie_chart = alignment_counts.plot(kind='pie', autopct='%1.1f%%', title='Alignment Distribution', ax=ax) # fill the code
24. To what the majority of superheroes are aligned with?¶
In [ ]:
# Enter your code here
25. Visualize Height Distribution¶
In [51]:
fig, ax = plt.subplots(figsize=(8, 8))
height_boxplot = df['height'].plot(kind='box', ax=ax, title='Height Distribution') # fill the code in the placeholder
In [ ]: