Platform
Resources
Pricing
Sign in
Get started
Nithya Shathish
Workspace
Fork
Published
By
Nithya Shathish
Edited
Feb 20, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data
=
d3
.
csv
(
url
,
crash
=>
(
{
// combine the date and time strings into one Date object
dateTime
:
d3
.
timeParse
(
'%m/%d/%Y'
)
(
crash
.
date
)
,
borough
:
crash
.
borough
,
zip
:
crash
.
zip
,
injured
:
+
crash
.
injured
,
// + converts the string to an int
killed
:
+
crash
.
killed
,
cause
:
crash
.
cause
}
)
)
Insert cell
Insert cell
md
`Write the low-level question here.`
//Has the number of kills or injuries (i.e the collisions) increased or decreased over time ?
// we need to know the number of collsions in each month to understand behaviors pattern
//Step 1 : Find out the number of collisions in each month
//Step 2 : analyse the data
Insert cell
//datac = data.filter(currentElement => data.filter (currentElement => currentElement.cause === "Unspecified"))
//data_d = data.filter(currentElement => currentElement.cause !== "Unspecified")
//newData = d3.group(data, d => d.cause)
//newData1 = d3.group(data, d => d.dat)
Insert cell
cleanedData
=
data
.
map
(
currentElement
=>
(
{
'Month'
:
currentElement
.
dateTime
.
getMonth
(
)
,
'injured'
:
currentElement
.
injured
,
'killed'
:
currentElement
.
killed
,
'cause'
:
currentElement
.
cause
,
}
)
)
Insert cell
// Each type of Collision
Insert cell
totalNumber
=
d3
.
rollup
(
cleanedData
,
v
=>
v
.
length
,
d
=>
d
.
Month
)
Insert cell
Insert cell
brandAndMedianRatings
=
Array
.
from
(
totalNum
,
(
[
month
,
accidents
]
)
=>
(
{
month
,
accidents
}
)
)
Insert cell
// From the above data we can concluded that in the 5th,6th and 7th month , the number of accidents have increased.
Insert cell
Insert cell
md
`Write the low-level question here.`
// We have find the number of collions per cause and try to find the Top 10 Causes of Collisions
Insert cell
cleaned_Data
=
data
.
map
(
currentElement
=>
(
{
'Month'
:
currentElement
.
dateTime
.
getMonth
(
)
,
'injured'
:
currentElement
.
injured
,
'killed'
:
currentElement
.
killed
,
'cause'
:
currentElement
.
cause
,
}
)
)
Insert cell
newdata
=
{
const
accumulator
=
{
}
;
for
(
let
i
=
0
;
i
<
cleaned_Data
.
length
;
i
++
)
{
const
currentValue
=
cleaned_Data
[
i
]
;
const
count
=
accumulator
[
currentValue
.
cause
]
||
0
;
accumulator
[
currentValue
.
cause
]
=
count
+
1
;
}
return
accumulator
;
}
Insert cell
Cause_data
=
d3
.
rollup
(
cleanedData
,
v
=>
v
.
length
,
d
=>
d
.
cause
)
Insert cell
brandToMedianRatinga
=
Array
.
from
(
Cause_data
,
function
(
pair
)
{
return
{
Cause
:
pair
[
0
]
,
number
:
pair
[
1
]
}
}
)
Insert cell
Top_cause_for_collisions
=
brandToMedianRatinga
.
slice
(
)
.
sort
(
(
a
,
b
)
=>
d3
.
descending
(
a
.
number
,
b
.
number
)
)
.
slice
(
0
,
15
)
Insert cell
//These are the top 15 causes for collisions
Insert cell
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.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
url
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
data
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
cleanedData
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
totalNumber
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
totalNum
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
brandAndMedianRatings
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
cleaned_Data
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
newdata
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Cause_data
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
brandToMedianRatinga
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Top_cause_for_collisions
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
d3
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML