Using Wikipedia tables in a survey

[1]:
from edsl import ScenarioList

Call the from_wikipedia method on a ScenarioList and pass (i) the URL for the Wikipedia page containing the table and (ii) the number of the table on the page (an integer starting at 0 that can be omitted if there is only 1 table on the page). For example, here we create scenarios for the 4th table at the page about movies of the 1990s:

[2]:
scenarios = ScenarioList.from_wikipedia("https://en.wikipedia.org/wiki/1990s_in_film", 3)
[3]:
scenarios
[3]:

ScenarioList scenarios: 50; keys: ['Rank', 'Worldwide gross', 'Ref.', 'Title', 'Studios', 'Year'];

RankTitle Studios Worldwide gross YearRef.
1Titanic Paramount Pictures/20th Century Fox $1,843,201,268 1997[# 1]
2Star Wars: Episode I – The Phantom Menace20th Century Fox $924,317,558 1999[# 2]
3Jurassic Park Universal Pictures $914,691,118 1993[# 3]
4Independence Day 20th Century Fox $817,400,891 1996[# 4]
5The Lion King Walt Disney Studios $763,455,561 1994[# 5]
6Forrest Gump Paramount Pictures $677,387,716 1994[# 6]
7The Sixth Sense Walt Disney Studios $672,806,292 1999[# 7]
8The Lost World: Jurassic Park Universal Pictures $618,638,999 1997[# 8]
9Men in Black Sony Pictures/Columbia Pictures $589,390,539 1997[# 9]
10Armageddon Walt Disney Studios $553,709,788 1998[# 10]
11Terminator 2: Judgment Day TriStar Pictures $519,843,345 1991[# 11]
12Ghost Paramount Pictures $505,702,588 1990[# 12]
13Aladdin Walt Disney Studios $504,050,219 1992[# 13]
14Twister Warner Bros./Universal Pictures $494,471,524 1996[# 14]
15Toy Story 2 Walt Disney Studios $485,015,179 1999[# 15]
16Saving Private Ryan DreamWorks Pictures/Paramount Pictures $481,840,909 1998[# 16]
17Home Alone 20th Century Fox $476,684,675 1990[# 17]
18The Matrix Warner Bros. $463,517,383 1999[# 18]
19Pretty Woman Walt Disney Studios $463,406,268 1990[# 19]
20Mission: Impossible Paramount Pictures $457,696,359 1996[# 20]
21Tarzan Walt Disney Studios $448,191,819 1999[# 21]
22Mrs. Doubtfire 20th Century Fox $441,286,195 1993[# 22]
23Dances with Wolves Orion Pictures $424,208,848 1990[# 23]
24The Mummy Universal Pictures $415,933,406 1999[# 24]
25The Bodyguard Warner Bros. $411,006,740 1992[# 25]
26Robin Hood: Prince of Thieves Warner Bros. $390,493,908 1991[# 26]
27Godzilla TriStar Pictures $379,014,294 1998[# 27]
28True Lies 20th Century Fox $378,882,411 1994[# 28]
29Toy Story Walt Disney Studios $373,554,033 1995[# 29]
30There's Something About Mary 20th Century Fox $369,884,651 1998[# 30]
31The Fugitive Warner Bros. $368,875,760 1993[# 31]
32Die Hard with a Vengeance 20th Century Fox/Cinergi Pictures $366,101,666 1995[# 32]
33Notting Hill PolyGram Filmed Entertainment $363,889,678 1999[# 33]
34A Bug's Life Walt Disney Studios $363,398,565 1998[# 34]
35The World Is Not Enough Metro-Goldwyn-Mayer Pictures $361,832,400 1999[# 35]
36Home Alone 2: Lost in New York 20th Century Fox $358,994,850 1992[# 36]
37American Beauty DreamWorks Pictures $356,296,601 1999[# 37]
38Apollo 13 Universal Pictures/Imagine Entertainment$355,237,933 1995[# 38]
39Basic Instinct TriStar Pictures $352,927,224 1992[# 39]
40GoldenEye MGM/United Artists $352,194,034 1995[# 40]
41The Mask New Line Cinema $351,583,407 1994[# 41]
42Speed 20th Century Fox $350,448,145 1994[# 42]
43Deep Impact Paramount Pictures/DreamWorks Pictures $349,464,664 1998[# 43]
44Beauty and the Beast Walt Disney Studios $346,317,207 1991[# 44]
45Pocahontas Walt Disney Studios $346,079,773 1995[# 45]
46The Flintstones Universal Pictures $341,631,208 1994[# 46]
47Batman Forever Warner Bros. $336,529,144 1995[# 47]
48The Rock Walt Disney Studios $335,062,621 1996[# 48]
49Tomorrow Never Dies MGM/United Artists $333,011,068 1997[# 49]
50Seven New Line Cinema $327,311,859 1995[# 50]
[4]:
scenarios.parameters
[4]:
{'Rank', 'Ref.', 'Studios', 'Title', 'Worldwide gross', 'Year'}
[5]:
from edsl import QuestionList

q_leads = QuestionList(
    question_name = "leads",
    question_text = "Who are the lead actors or actresses in {{ Title }}?"
)

results = q_leads.by(scenarios).run()

(
    results
    .sort_by("Title")
    .select("Title", "leads")
)
[5]:
scenario.Title answer.leads
A Bug's Life ['Dave Foley', 'Kevin Spacey', 'Julia Louis-Dreyfus', 'Hayden Panettiere']
Aladdin ['Mena Massoud', 'Naomi Scott', 'Will Smith']
American Beauty ['Kevin Spacey', 'Annette Bening', 'Thora Birch', 'Wes Bentley', 'Mena Suvari']
Apollo 13 ['Tom Hanks', 'Bill Paxton', 'Kevin Bacon']
Armageddon ['Bruce Willis', 'Ben Affleck', 'Liv Tyler', 'Billy Bob Thornton']
Basic Instinct ['Michael Douglas', 'Sharon Stone']
Batman Forever ['Val Kilmer', 'Tommy Lee Jones', 'Jim Carrey', 'Nicole Kidman', "Chris O'Donnell"]
Beauty and the Beast ['Emma Watson', 'Dan Stevens']
Dances with Wolves ['Kevin Costner', 'Mary McDonnell', 'Graham Greene', 'Rodney A. Grant']
Deep Impact ['Robert Duvall', 'Téa Leoni', 'Elijah Wood', 'Morgan Freeman', 'Vanessa Redgrave']
Die Hard with a Vengeance ['Bruce Willis', 'Samuel L. Jackson', 'Jeremy Irons']
Forrest Gump ['Tom Hanks', 'Robin Wright', 'Gary Sinise', 'Sally Field', 'Mykelti Williamson']
Ghost ['Patrick Swayze', 'Demi Moore', 'Whoopi Goldberg']
Godzilla ['Aaron Taylor-Johnson', 'Elizabeth Olsen', 'Bryan Cranston']
GoldenEye ['Pierce Brosnan', 'Sean Bean', 'Izabella Scorupco', 'Famke Janssen']
Home Alone ['Macaulay Culkin', 'Joe Pesci', 'Daniel Stern', "Catherine O'Hara", 'John Heard']
Home Alone 2: Lost in New York ['Macaulay Culkin', 'Joe Pesci', 'Daniel Stern', "Catherine O'Hara", 'John Heard']
Independence Day ['Will Smith', 'Bill Pullman', 'Jeff Goldblum']
Jurassic Park ['Sam Neill', 'Laura Dern', 'Jeff Goldblum', 'Richard Attenborough']
Men in Black ['Will Smith', 'Tommy Lee Jones']
Mission: Impossible ['Tom Cruise']
Mrs. Doubtfire ['Robin Williams', 'Sally Field', 'Pierce Brosnan', 'Harvey Fierstein', 'Lisa Jakub']
Notting Hill ['Hugh Grant', 'Julia Roberts']
Pocahontas ['Irene Bedard', 'Mel Gibson']
Pretty Woman ['Richard Gere', 'Julia Roberts']
Robin Hood: Prince of Thieves ['Kevin Costner', 'Morgan Freeman', 'Mary Elizabeth Mastrantonio', 'Christian Slater', 'Alan Rickman']
Saving Private Ryan ['Tom Hanks', 'Matt Damon', 'Edward Burns', 'Tom Sizemore', 'Barry Pepper']
Seven ['Brad Pitt', 'Morgan Freeman', 'Gwyneth Paltrow']
Speed ['Keanu Reeves', 'Sandra Bullock', 'Dennis Hopper']
Star Wars: Episode I – The Phantom Menace['Liam Neeson', 'Ewan McGregor', 'Natalie Portman', 'Jake Lloyd']
Tarzan ['Johnny Weissmuller', "Maureen O'Sullivan", 'Tony Goldwyn', 'Minnie Driver']
Terminator 2: Judgment Day ['Arnold Schwarzenegger', 'Linda Hamilton', 'Edward Furlong', 'Robert Patrick']
The Bodyguard ['Kevin Costner', 'Whitney Houston']
The Flintstones ['John Goodman', 'Elizabeth Perkins', 'Rick Moranis', "Rosie O'Donnell"]
The Fugitive ['Harrison Ford', 'Tommy Lee Jones']
The Lion King ['Matthew Broderick', 'James Earl Jones', 'Jeremy Irons', 'Moira Kelly', 'Nathan Lane', 'Ernie Sabella', 'Whoopi Goldberg']
The Lost World: Jurassic Park ['Jeff Goldblum', 'Julianne Moore', 'Vince Vaughn']
The Mask ['Jim Carrey', 'Cameron Diaz']
The Matrix ['Keanu Reeves', 'Laurence Fishburne', 'Carrie-Anne Moss', 'Hugo Weaving']
The Mummy ['Brendan Fraser', 'Rachel Weisz', 'John Hannah', 'Arnold Vosloo']
The Rock ['Sean Connery', 'Nicolas Cage', 'Ed Harris']
The Sixth Sense ['Bruce Willis', 'Haley Joel Osment', 'Toni Collette']
The World Is Not Enough ['Pierce Brosnan', 'Sophie Marceau', 'Robert Carlyle', 'Denise Richards']
There's Something About Mary ['Cameron Diaz', 'Ben Stiller', 'Matt Dillon']
Titanic ['Leonardo DiCaprio', 'Kate Winslet']
Tomorrow Never Dies ['Pierce Brosnan', 'Michelle Yeoh', 'Teri Hatcher']
Toy Story ['Tom Hanks', 'Tim Allen']
Toy Story 2 ['Tom Hanks', 'Tim Allen', 'Joan Cusack']
True Lies ['Arnold Schwarzenegger', 'Jamie Lee Curtis']
Twister ['Helen Hunt', 'Bill Paxton']

Posting to the Coop

[6]:
scenarios.push(description = "Wikipedia: 1990s in film - List of worldwide highest-grossing films", visibility = "public")
[6]:
{'description': 'Wikipedia: 1990s in film - List of worldwide highest-grossing films',
 'object_type': 'scenario_list',
 'url': 'https://www.expectedparrot.com/content/a49fe6b4-5638-46e7-aa44-7c970c50975e',
 'uuid': 'a49fe6b4-5638-46e7-aa44-7c970c50975e',
 'version': '0.1.39.dev1',
 'visibility': 'public'}
[7]:
from edsl import Notebook
[8]:
n = Notebook(path = "scenario_list_wikipedia.ipynb")
[9]:
info = n.push(description = "Example code for generating scenarios from Wikipedia tables", visibility = "public")

Updating an object at the Coop

[10]:
n = Notebook(path = "scenario_list_wikipedia.ipynb")
[11]:
n.patch(info["uuid"], value = n)
[11]:
{'status': 'success'}