Public
Edited
May 30, 2023
Fork of Final Report
1 fork
Insert cell
Insert cell
hotel_bookings.csv
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Wrangler(hotel_bookings)
Insert cell
// To use copied code replace "data" with your own variable
data_hotel = aq
.from(hotel_bookings)
.select(
"hotel",
"arrival_date_month",
"arrival_date_day_of_month",
"stays_in_weekend_nights",
"adults",
"children",
"babies",
"country"
)
.derive({ "Travel Type": Travel_type })
.derive({ "Season" : Season_classification})
.derive({ "Hotel_Type": hotel_type})
.objects()
Insert cell
count_resort = hotel_bookings.filter(d => d["hotel"] == "Resort Hotel")
Insert cell
count_city = hotel_bookings.filter(d => d["hotel"] == "City Hotel")
Insert cell
hotel_type = (d) => {
if (d["hotel"] === "City Hotel") {
return "City Hotel";
}
if (d["hotel"] === "Resort Hotel") {
return "Resort Hotel";
}
}
Insert cell
Travel_type = (d) => {
if (d["adults"] >= 1 && (d["children"] > 0) | (d["babies"] > 0)) {
return "Family";
}
if (d["adults"] === 1 && (d["children"] === 0) | (d["babies"] === 0)) {
return "Alone";
}
if (d["adults"] > 2 && (d["children"] === 0) | (d["babies"] === 0)) {
return "Friends Group";
}
if (d["adults"] === 2 && (d["children"] === 0) | (d["babies"] === 0)) {
return "Pair";
}
}
Insert cell
Season_classification = (d) => {
if (d["arrival_date_month"] === "March") {
return "Spring";
}
if (d["arrival_date_month"] === "April") {
return "Spring";
}
if (d["arrival_date_month"] === "May") {
return "Spring";
}
if (d["arrival_date_month"] === "June") {
return "Summer";
}
if (d["arrival_date_month"] === "July") {
return "Summer";
}
if (d["arrival_date_month"] === "August") {
return "Summer";
}
if (d["arrival_date_month"] === "September") {
return "Autumn";
}
if (d["arrival_date_month"] === "October") {
return "Autumn";
}
if (d["arrival_date_month"] === "November") {
return "Autumn";
}
if (d["arrival_date_month"] === "December") {
return "Winter";
}
if (d["arrival_date_month"] === "January") {
return "Winter";
}
if (d["arrival_date_month"] === "February") {
return "Winter";
}




}
Insert cell
Plot.plot({
marks: [
Plot.ruleY([0]),
Plot.lineY(hotel_bookings, {
x: "arrival_date_month",
y: hotel_bookings.filter((d) => d["hotel"] == "Resort Hotel").length
})
]
})
Insert cell
Plot.plot({
grid: true,
nice: true,
marks: [
Plot.barY(data_hotel, {
x: travel_types,
y: count_travelType,
fill: (d) => {
if (op.endswith(travel_types, "City") === "City") {
return "Grey";
} else {
return "Orange";
}
},

sort: { x: "y", reverse: true }
}),
Plot.ruleY([0])
]
})
Insert cell
originAndStays = FileAttachment("Origin and Stays.twbx")
Insert cell
count_travelType = [
count_pairCity,
count_pairResort,

count_aloneCity,
count_aloneResort,

count_familyCity,
count_familyResort,

count_friendsGroupCity,
count_friendsGroupResort
]
Insert cell
travel_types = [
"Pair City",
"Pair Resort",
"Alone City",
"Alone Resort",
"Family City",
"Alone Resort",
"Friends Group City",
"Friends Group Resort"
]
Insert cell
count_pair = data_hotel.filter((d) => d["Travel Type"] === "Pair")
Insert cell
count_pairResort = count_pair.filter((d) => d["hotel"] === "Resort Hotel")
.length
Insert cell
count_pairCity = count_pair.filter((d) => d["hotel"] === "City Hotel").length
Insert cell
count_family = data_hotel.filter((d) => d["Travel Type"] === "Family")
Insert cell
count_familyResort = count_family.filter((d) => d["hotel"] === "Resort Hotel")
.length
Insert cell
count_familyCity = count_family.filter((d) => d["hotel"] === "City Hotel")
.length
Insert cell
count_friendsGroup = data_hotel.filter(
(d) => d["Travel Type"] === "Friends Group"
)
Insert cell
count_friendsGroupResort = count_friendsGroup.filter(
(d) => d["hotel"] === "Resort Hotel"
).length
Insert cell
count_friendsGroupCity = count_friendsGroup.filter(
(d) => d["hotel"] === "City Hotel"
).length
Insert cell
count_alone = data_hotel.filter((d) => d["Travel Type"] === "Alone")
Insert cell
count_aloneResort = count_alone.filter((d) => d["hotel"] === "Resort Hotel")
.length
Insert cell
count_aloneCity = count_alone.filter((d) => d["hotel"] === "City Hotel").length
Insert cell
viewof travel_type = Inputs.checkbox(
new Map([["Pair"], ["Alone"], ["Family"], ["Friends Group"]]),
{
value: [12],
label: "Travel Type",
format: ([name, value]) => `${name}`
}
)
Insert cell
import { Wrangler, op } from "@observablehq/data-wrangler"
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