This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import geojson | |
with open("data/input.csv", 'wb') as f: | |
f.write(response.content) | |
# Create GeoJSON file. | |
df = pd.read_csv('data/input.csv', | |
skiprows=4, | |
dtype={ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
df = pd.read_csv("./data/horror_films.csv") | |
df.drop_duplicates(inplace=True) | |
table = pd.pivot_table(data=df,index='Setting', values='Film', aggfunc='count') | |
table.to_csv("./data/cleaned_horror_films.csv") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import folium | |
import pandas as pd | |
# Cleaning the data. | |
df = pd.read_csv("../data/horror_films.csv") | |
df.drop_duplicates(inplace=True) | |
table = pd.pivot_table(data=df,index='Setting', values='Film', aggfunc='count') | |
table.to_csv("../data/cleaned_horror_films.csv") | |
# Creating the map. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
colours = ['red', 'green', ['cobalt', 'teal', 'blue']] | |
colours_copy = copy.deepcopy(colours) | |
colours[2].append('sky') | |
colours_copy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
colours = ['red', 'green', ['cobalt', 'teal', 'blue']] | |
colours_copy = colours[:] | |
colours[2].append('sky') | |
colours_copy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import copy | |
# Using slice syntax | |
car_brands = ['Toyota', 'Ford', 'Honda'] | |
car_brands_copy = car_brands[:] | |
# Using the copy module | |
car_brands = ['Toyota', 'Ford', 'Honda'] | |
car_brands_copy = copy.copy(watch_brands) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
os.remove('example.txt') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Writing results to CSV file. | |
with open("data/horror_films.csv", "w") as file_object: | |
writer = csv.DictWriter(file_object, fieldnames=["Film", "Year released", | |
"Setting"]) | |
writer.writeheader() | |
for film in horror_films_with_states: | |
for location in film.setting: | |
writer.writerow( | |
{ | |
"Film": film.title, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check to see which horror films are set in which US states. | |
horror_films_with_states = [] | |
for film in states_films: | |
if film in horror_films and film.year_released is None: | |
film.year_released = horror_films[horror_films.index(film)].year_released | |
horror_films_with_states.append(film) | |
elif film in horror_films and film.year_released is not None: | |
horror_films_with_states.append(film) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Film: | |
def __init__(self, title, year_released=None, setting=None): | |
self.title = title | |
self.year_released = year_released | |
self.setting = {setting} |
NewerOlder