Published
Edited
Dec 28, 2020
2 forks
Insert cell
md `# Housing Loan Blank Examples`
Insert cell
md `## Load library d3 and lodash`
Insert cell
_ = require('lodash')
Insert cell
d3 = require("d3@v5")
Insert cell
md `## Load csv as JSON array of objects`
Insert cell
data = FileAttachment("houseloan.csv").csv({typed: true})
Insert cell
md `### 1. Filter by city Ipoh, sorted

Use the following array functions :
- filter
- sort

Name your results **myLoan**
`
Insert cell
md `### 2. Filter by city IPOH, sorted

Use the following array functions :
- filter
- sort

Name your results **myLoan2**
`
Insert cell
md `### 3. Use map() to extract myLoan to json format for charting purposes.
name = property type

value = MG_SnP / 1000

Example data :
** { name: "Bungalow", value: 3302 } **
`
Insert cell
md `### 4. List Property Type using lodash uniqBy() and map()

Sample Results

[
0: "Terrace House"
1: "Apartment"
2: "Semi-Detached"
3: "Condominium"
4: "Bungalow"
5: "Town House"
6: "Condo"
7: "Shop/Office"
8: "Shophouse/Shop office/Shop lot/Retail lot"
9: "Flat"
10: "Townhouse"
11: "Commercial/Shopping Complex"
12: "Penthouse"
]
`
Insert cell
md `### 5. List all cities _.uniqBy with _.toUpper()
Prevent strings like Ipoh or IPOH

Name this **propertyCity**

propertyCity = _.uniqBy(data, d => _.toUpper(d.City_Nm))
.map( d => _.toUpper(d.City_Nm) )
.sort()

`
Insert cell
md `### 6. List all States uniqBy with _.toUpper()
Prevent strings like Selangor or SELANGOR

Name this **propertyState**


`
Insert cell
propertyState = _.uniqBy(data, d => _.toUpper(d.Property_State))
Insert cell
md `### 7. Properties count by cities`
Insert cell
md `### 8. Filter by City of Pulau Pinang,
return city name and each property value in a jSON

{ city: "PULAU PINANG", value: 702 }

`
Insert cell
md `### 9. Use reduce to count the total value for each city`
Insert cell
md `### 10. Use reduce to find the max value `
Insert cell
md `### 11. Use reduce to find the min value`
Insert cell
md `### Do your queries here ...

- Which cities have the highest value ?
- Which cities have the most categories ?
- Which housing type most expensive ?
- Which housing type most popular ?

`
Insert cell
md `## 12. Use data from cityCount into bar charts

Below is a sample chart with name, value pairs`
Insert cell
sampleData = [
{
name: "a",
value: 10
},
{
name: "b",
value: 8
},
{
name: "c",
value: 1
},
]
Insert cell
import {chart as barChart} with { sampleData as data } from '@d3/bar-chart'
Insert cell
barChart
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