# Import modules
import pandas as pd
# Set ipython's max row display
pd.set_option('display.max_row', 1000)
# Set iPython's max column width to 50
pd.set_option('display.max_columns', 50)
# Load example dataset
df = pd.read_csv('https://www.dropbox.com/s/52cb7kcflr8qm2u/5kings_battles_v1.csv?dl=1')
# Create variable with TRUE if stark is the attacker
stark_attacker = df['attacker_king'] == "Robb Stark"
# Create variable with TRUE if the attacker wins
attacker_wins = df['attacker_outcome'] == "win"
# Select all cases where stark is the attacker and the attacker wins
df[stark_attacker & attacker_wins]
name | year | battle_number | attacker_king | defender_king | attacker_1 | attacker_2 | attacker_3 | attacker_4 | defender_1 | defender_2 | defender_3 | defender_4 | attacker_outcome | battle_type | major_death | major_capture | attacker_size | defender_size | attacker_commander | defender_commander | summer | location | region | note | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
4 | Battle of the Whispering Wood | 298 | 5 | Robb Stark | Joffrey/Tommen Baratheon | Stark | Tully | NaN | NaN | Lannister | NaN | NaN | NaN | win | ambush | 1 | 1 | 1875 | 6000 | Robb Stark, Brynden Tully | Jaime Lannister | 1 | Whispering Wood | The Riverlands | NaN |
5 | Battle of the Camps | 298 | 6 | Robb Stark | Joffrey/Tommen Baratheon | Stark | Tully | NaN | NaN | Lannister | NaN | NaN | NaN | win | ambush | 0 | 0 | 6000 | 12625 | Robb Stark, Tytos Blackwood, Brynden Tully | Lord Andros Brax, Forley Prester | 1 | Riverrun | The Riverlands | NaN |
10 | Battle of Torrhen's Square | 299 | 11 | Robb Stark | Balon/Euron Greyjoy | Stark | NaN | NaN | NaN | Greyjoy | NaN | NaN | NaN | win | pitched battle | 0 | 0 | 244 | 900 | Rodrik Cassel, Cley Cerwyn | Dagmer Cleftjaw | 1 | Torrhen's Square | The North | Greyjoy's troop number comes from the 264 esti... |
14 | Battle of Oxcross | 299 | 15 | Robb Stark | Joffrey/Tommen Baratheon | Stark | Tully | NaN | NaN | Lannister | NaN | NaN | NaN | win | ambush | 1 | 1 | 6000 | 10000 | Robb Stark, Brynden Tully | Stafford Lannister, Roland Crakehall, Antario ... | 1 | Oxcross | The Westerlands | NaN |
17 | Sack of Harrenhal | 299 | 18 | Robb Stark | Joffrey/Tommen Baratheon | Stark | NaN | NaN | NaN | Lannister | NaN | NaN | NaN | win | ambush | 1 | 0 | 100 | 100 | Roose Bolton, Vargo Hoat, Robett Glover | Amory Lorch | 1 | Harrenhal | The Riverlands | NaN |
18 | Battle of the Crag | 299 | 19 | Robb Stark | Joffrey/Tommen Baratheon | Stark | NaN | NaN | NaN | Lannister | NaN | NaN | NaN | win | ambush | 0 | 0 | 6000 | NaN | Robb Stark, Smalljon Umber, Black Walder Frey | Rolph Spicer | 1 | Crag | The Westerlands | NaN |
20 | Siege of Darry | 299 | 21 | Robb Stark | Joffrey/Tommen Baratheon | Darry | NaN | NaN | NaN | Lannister | NaN | NaN | NaN | win | siege | 0 | 0 | NaN | NaN | Helman Tallhart | NaN | 1 | Darry | The Riverlands | NaN |
26 | Siege of Seagard | 299 | 27 | Robb Stark | Joffrey/Tommen Baratheon | Frey | NaN | NaN | NaN | Mallister | NaN | NaN | NaN | win | siege | 0 | 1 | NaN | NaN | Walder Frey | Jason Mallister | 1 | Seagard | The Riverlands | NaN |
# Select the rows where attacker_2 is not missing, and defender_2 is not missing
df[df['attacker_2'].notnull() & df['defender_2'].notnull()]
name | year | battle_number | attacker_king | defender_king | attacker_1 | attacker_2 | attacker_3 | attacker_4 | defender_1 | defender_2 | defender_3 | defender_4 | attacker_outcome | battle_type | major_death | major_capture | attacker_size | defender_size | attacker_commander | defender_commander | summer | location | region | note | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
27 | Battle of Castle Black | 300 | 28 | Stannis Baratheon | Mance Rayder | Free folk | Thenns | Giants | NaN | Night's Watch | Baratheon | NaN | NaN | loss | siege | 1 | 1 | 100000 | 1240 | Stannis Baratheon, Jon Snow, Donal Noye, Cotte... | Mance Rayder, Tormund Giantsbane, Harma Dogshe... | 0 | Castle Black | Beyond the Wall | NaN |
37 | Siege of Winterfell | 300 | 38 | Stannis Baratheon | Joffrey/Tommen Baratheon | Baratheon | Karstark | Mormont | Glover | Bolton | Frey | NaN | NaN | NaN | NaN | NaN | NaN | 5000 | 8000 | Stannis Baratheon | Roose Bolton | 0 | Winterfell | The North | NaN |