Find nearest film scene location in NYC




Pay Notebook Creator: Eva Wang11
Set Container: Numerical CPU with TINY Memory for 10 Minutes 0
Total0
In [4]:
import pandas as pd
In [38]:
t = pd.read_csv('Interactive_Map_Data.csv', encoding='latin-1', skiprows=1)
In [41]:
t[:3]
Out[41]:
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style>
Film Year URL Encoded name Image File Name Agency Credit Artist Credit Director/Filmmaker Name Director/Filmmaker IMDB Link Location Display Text LATITUDE ... Neighborhood Scene Type Media IMDB LINK Client or book location indicator Notes Book Image Book Page Display? IMAGE OF LOCATION
0 *batteries not included 1987 %2Abatteries%20not%20included batteriesnotincluded_pf Courtesy of Photofest Directed by Matthew Robbins http://imdb.com/name/nm0730422/ E. 5th St.<br>East Village<br>Manhattan 40.722445 ... East Village NaN Film http://imdb.com/title/tt0092494/ NaN NaN Y 190 NaN Y
1 12 Angry Men 1957 12%20Angry%20Men 12AngryMen_pf Courtesy of Photofest Directed by Sidney Lumet http://imdb.com/name/nm0001486/ New York County Courthouse<br>40 Foley Square<... 40.713700 ... Lower Manhattan NaN Film http://imdb.com/title/tt0050083/ New York County\nCourthouse on Foley Square. NaN Y 40 NaN Y
2 13 Going on 30 2004 13%20Going%20on%2030 13Goingon30_ec Courtesy of Everett Collection, Inc. Directed by Gary Winick http://imdb.com/name/nm0935095/ W. 47th St. and Seventh Ave.<br>Times Square<b... 40.759220 ... Times Square NaN Film http://www.imdb.com/title/tt0337563/ 47th St. and 7th Ave. Times Square\nManhattan NaN Y 239 NaN Y
<p>3 rows × 22 columns</p>
In [43]:
t[(t['Film'] == '12 Angry Men') | (t['Film'] == '13 Going on 30')]
Out[43]:
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style>
Film Year URL Encoded name Image File Name Agency Credit Artist Credit Director/Filmmaker Name Director/Filmmaker IMDB Link Location Display Text LATITUDE ... Neighborhood Scene Type Media IMDB LINK Client or book location indicator Notes Book Image Book Page Display? IMAGE OF LOCATION
1 12 Angry Men 1957 12%20Angry%20Men 12AngryMen_pf Courtesy of Photofest Directed by Sidney Lumet http://imdb.com/name/nm0001486/ New York County Courthouse<br>40 Foley Square<... 40.71370 ... Lower Manhattan NaN Film http://imdb.com/title/tt0050083/ New York County\nCourthouse on Foley Square. NaN Y 40 NaN Y
2 13 Going on 30 2004 13%20Going%20on%2030 13Goingon30_ec Courtesy of Everett Collection, Inc. Directed by Gary Winick http://imdb.com/name/nm0935095/ W. 47th St. and Seventh Ave.<br>Times Square<b... 40.75922 ... Times Square NaN Film http://www.imdb.com/title/tt0337563/ 47th St. and 7th Ave. Times Square\nManhattan NaN Y 239 NaN Y
<p>2 rows × 22 columns</p>
In [ ]:
film_names = [
    '12 Angry Men',
    '13 Going on 30',
]
film_filter
In [6]:
t.columns
Out[6]:
Index(['Film', 'Year', 'URL Encoded name', 'Image File Name', 'Agency Credit',
       'Artist Credit', 'Director/Filmmaker Name',
       'Director/Filmmaker IMDB Link', 'Location Display Text', 'LATITUDE',
       'LONGITUDE', 'Borough', 'Neighborhood', 'Scene Type', 'Media',
       'IMDB LINK', 'Client or book location indicator', 'Notes', 'Book Image',
       'Book Page', 'Display?', 'IMAGE OF LOCATION'],
      dtype='object')
In [9]:
# Get distance between two points
from geopy.distance import vincenty as get_distance
get_distance
In [17]:
from geopy.distance import vincenty as get_distance
newport_ri = 41.49008, -71.312796
cleveland_oh = 41.499498, -81.695391
x = get_distance(newport_ri, cleveland_oh)
x
Out[17]:
Distance(866.4554329011002)
In [18]:
x.meters
Out[18]:
866455.4329011001
In [14]:
# Convert address to longitude and latitude
import geopy
geocode = geopy.GoogleV3('AIzaSyDNqc0tWzXHx_wIp1w75-XTcCk4BSphB5w').geocode
location = geocode('10025')
location
Out[14]:
Location(New York, NY 10025, USA, (40.7999209, -73.96831019999999, 0.0))
In [16]:
location_ll = location.latitude, location.longitude
location_ll
Out[16]:
(40.7999209, -73.96831019999999)
In [22]:
# Add column to table
import pandas as pd
t = pd.DataFrame([
    [1, 2],
    [3, 4],
], columns=['a', 'b'])
t
Out[22]:
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style>
a b
0 1 2
1 3 4
In [23]:
t['c'] = [3, 5]
In [24]:
t
Out[24]:
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style>
a b c
0 1 2 3
1 3 4 5
In [27]:
# Sort table by column
t.sort_values(['c'], ascending=False)
Out[27]:
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style>
a b c
1 3 4 5
0 1 2 3
In [33]:
def f(row):
    return row['a'] + row['b'] + row['c']

t['d'] = t.apply(f, axis=1)
t
Out[33]:
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style>
a b c d
0 1 2 3 6
1 3 4 5 12
In [35]:
t.sort_values(['d'], ascending=False)
Out[35]:
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style>
a b c d
1 3 4 5 12
0 1 2 3 6
In [36]:
t
Out[36]:
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style>
a b c d
0 1 2 3 6
1 3 4 5 12
In [ ]:
# Add column that is the distance of each row from the geocoded address
In [ ]:
# Define address as a user argument in the first code cell
# Get latitude and longitude of the address
# Define function that computes distance of each row from the geocoded address
# Sort table by distance
# Get first six or seven rows of the table
# Save first six or seven rows of the table on the map
# Show the map
In [ ]: