Public
Edited
Feb 6, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
horror_movies.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Insert cell
Insert cell
d3 = require("d3@7")
Insert cell
import {vl} from '@vega/vega-lite-api'
Insert cell
movie = d3.csv("https://raw.githubusercontent.com/SooaMo/data/main/horror_movies.csv")
Insert cell
Insert cell
movieParsed = {
for (let i=0;i<movie.length;i++)
{
movie[i].title = +movie[i].title;
movie[i].original_language = +movie[i].originalLanguage;
movie[i].overview = +movie[i].overview;
movie[i].tagline = +movie[i].tagline;
movie[i].release_date = +movie[i].releaseDate;
movie[i].popularity = +movie[i].popularity;
movie[i].vote_count = +movie[i].vote_count;
movie[i].vote_average = +movie[i].vote_average;
movie[i].budget = +movie[i].budget;
movie[i].revenue = +movie[i].revenue;
movie[i].runtime = +movie[i].runtime;
movie[i].status = +movie[i].status;
movie[i].adult = +movie[i].adult;
movie[i].genre_names = +movie[i].genre_names;
}
return movie;
}
Insert cell
Insert cell
//find the max runtime

runtimeMax = {
let i=0;
let maxRuntime=0;
for (i=0;i<movie.length;i++){
if (movie[i].runtime > maxRuntime){
maxRuntime = movie[i].runtime;
}
}
return maxRuntime;
}
Insert cell
runtimeMin = {
let i = 1;
let minRuntime = movie[0].runtime;

for (i=1;i<movie.length;i++){
//without 0. The dataset was probably written based on minutes, and movies in less than a minute were most likely expressed as zero. That's why I try to get 1 instead of 0.
if(movie[i].runtime>0){
if (movie[i].runtime < minRuntime){
minRuntime = movie[i].runtime;
}
}
}
return minRuntime;
}
Insert cell
Insert cell
sumRuntime = {
let totalSum = d3.sum(movie, function(d){return +d.runtime})
return totalSum.toFixed(2)
}
Insert cell
Insert cell
//average a set of runtime
avgRuntime = {
return d3.mean(sumRuntime).toFixed(2);
}
Insert cell
//average a set of runtime without some movie which has 0 value.
averageRuntime = {
let NotZeroRuntime = movie.filter(function(d){ return d.Runtime != 0});
let NotZeroRuntimeMovie = NotZeroRuntime.map(function(d){return +d.runtime});
return d3.mean(NotZeroRuntimeMovie).toFixed(2);
}
Insert cell
Insert cell
countRuntime= movie.filter(d=>(d.runtime>60 && d.runtime<120)).length
Insert cell
Insert cell
vl.markBar()
.data(movie)
.encode(
vl.x().fieldQ('runtime').bin({step:60}),
vl.y().count()
)
.render()
Insert cell
vl.markBar()
.data(movie)
.encode(
vl.x().fieldQ('runtime').bin({step:30}),
vl.y().count()
)
.render()
Insert cell
vl.markBar()
.data(movie)
.encode(
vl.x().fieldQ('runtime').bin({step:10}),
vl.y().count()
)
.render()
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more