Skip to content

Instantly share code, notes, and snippets.

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={
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")
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.
colours = ['red', 'green', ['cobalt', 'teal', 'blue']]
colours_copy = copy.deepcopy(colours)
colours[2].append('sky')
colours_copy
colours = ['red', 'green', ['cobalt', 'teal', 'blue']]
colours_copy = colours[:]
colours[2].append('sky')
colours_copy
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)
import os
os.remove('example.txt')
# 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,
# 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)
class Film:
def __init__(self, title, year_released=None, setting=None):
self.title = title
self.year_released = year_released
self.setting = {setting}