Public
Edited
Feb 19, 2024
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = {
const parseDate = d3.timeParse("%b %d %Y");
let file_data = await FileAttachment("msu_2021_record@1.csv").csv({typed: true});
file_data = file_data.reverse();
file_data.map((d,i) => {
d.date = parseDate(d.date);
d.won = d.runs_scored > d.runs_allowed;
if (i === 0) {
d.runs_scored_total = d.runs_scored;
d.runs_allowed_total = d.runs_allowed;
d.wins = d.won ? 1 : 0;
d.losses = d.won ? 0 : 1;
} else {
d.runs_scored_total = d.runs_scored + file_data[i-1].runs_scored_total;
d.runs_allowed_total = d.runs_allowed + file_data[i-1].runs_allowed_total;
d.wins = d.won ? file_data[i-1].wins + 1 : file_data[i-1].wins;
d.losses = d.won ? file_data[i-1].losses : file_data[i-1].losses + 1;
}
});
return file_data;

}
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