Last active
December 28, 2020 01:40
-
-
Save egoing/43799f48b55b5eb2a8b37652eab72318 to your computer and use it in GitHub Desktop.
danfo.js example - http://bit.ly/danfojs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/index.min.js"></script> | |
</head> | |
<body> | |
<div id="s_table"></div> | |
<div id="s_line"></div> | |
<div id="d_table"></div> | |
<div id="d_line"></div> | |
<script> | |
// 시리즈 생성 https://danfo.jsdata.org/getting-started#object-creation | |
var s = new dfd.Series([20, 21, 22, 23]); | |
s.print(); | |
// 시리즈 API https://danfo.jsdata.org/api-reference/series | |
s.describe().print(); | |
// 시각화 https://danfo.jsdata.org/api-reference/plotting | |
s.plot('s_table').table(); | |
s.plot('s_line').line(); | |
// 데이터프래임 생성 https://danfo.jsdata.org/getting-started#object-creation | |
// 배열 방식 | |
var d1 = new dfd.DataFrame([ | |
{'온도':20, '요일':'월', '판매량':40}, | |
{'온도':21, '요일':'월', '판매량':42}, | |
{'온도':22, '요일':'월', '판매량':44}, | |
{'온도':23, '요일':'월', '판매량':46} | |
]); | |
d1.print(); | |
// 객체 방식 | |
var d2 = new dfd.DataFrame({ | |
'온도':[20,21,22,23], | |
'요일':['월', '월', '월', '월'], | |
'판매량':[40,42,44,46] | |
}); | |
d2.print(); | |
// 파일로부터 데이터프래임 생성 https://danfo.jsdata.org/api-reference/input-output | |
// dfd.read_csv('https://gist.githubusercontent.com/egoing/43799f48b55b5eb2a8b37652eab72318/raw/3a207dd85d0b74968426e65ae2cee4cb1d4aef4f/lemon.csv') | |
// .then(function(data){// | |
// data.print(); | |
// }); | |
d1.describe().print(); | |
d1.plot('d_table').table(); | |
d1.plot('d_line').line(); | |
d1.print(); | |
// 데이터 선택 https://danfo.jsdata.org/getting-started#selection | |
var s = new dfd.Series([20, 21, 22, 23]); | |
console.log(s, d1['온도'], d1); // s와 d1['온도']는 Series이다. | |
// label of content https://danfo.jsdata.org/api-reference/dataframe/danfo.dataframe.loc | |
d1.loc({columns:['온도', '판매량']}).print(); | |
d1.loc({rows:[1,3]}).print(); | |
d1.loc({columns:['온도', '판매량'], rows:[1,3]}).print(); | |
// 논리비교를 이용한 필터링 https://danfo.jsdata.org/api-reference/dataframe/danfo.dataframe.query | |
d1 | |
.query({ "column": "온도", "is": ">", "to": 20 }) | |
.print(); | |
d1 | |
.query({ "column": "온도", "is": ">", "to": 20 }) | |
.query({ "column": "판매량", "is": "<", "to": 46 }) | |
.print(); | |
// 행 추가 | |
var newRow = new dfd.DataFrame({'온도':[24,25], '요일':['월','월'], '판매량':[48,50]}); | |
d1.append(newRow).print(); | |
// 열 추가 | |
d1.addColumn({ "column": "비", "value": [1,0,1,0]}); | |
d1.print(); | |
// 행삭제 | |
d1.drop({axis:0, index:[0]}).print(); | |
// 열삭제 | |
d1.drop({axis:1, columns:['온도']}).print(); | |
// to Array | |
d1.to_json().then(function(json){ | |
console.log(JSON.parse(json)) | |
}); | |
d1.tensor.print(); | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/index.min.js"></script> | |
</head> | |
<body> | |
<div id="s_table"></div> | |
<div id="s_line"></div> | |
<div id="d_table"></div> | |
<div id="d_line"></div> | |
<script> | |
// 시리즈 생성 https://danfo.jsdata.org/getting-started#object-creation | |
// var s = new dfd.Series([20, 21, 22, 23]); | |
// s.print(); | |
// 시리즈 API https://danfo.jsdata.org/api-reference/series | |
// s.describe().print(); | |
// 시각화 https://danfo.jsdata.org/api-reference/plotting | |
// s.plot('s_table').table(); | |
// s.plot('s_line').line(); | |
// 데이터프래임 생성 https://danfo.jsdata.org/getting-started#object-creation | |
// 배열 방식 | |
// var d1 = new dfd.DataFrame([ | |
// {'온도':20, '요일':'월', '판매량':40}, | |
// {'온도':21, '요일':'월', '판매량':42}, | |
// {'온도':22, '요일':'월', '판매량':44}, | |
// {'온도':23, '요일':'월', '판매량':46} | |
// ]); | |
// d1.print(); | |
// 객체 방식 | |
// var d2 = new dfd.DataFrame({ | |
// '온도':[20,21,22,23], | |
// '요일':['월', '월', '월', '월'], | |
// '판매량':[40,42,44,46] | |
// }); | |
// d2.print(); | |
// 파일로부터 데이터프래임 생성 https://danfo.jsdata.org/api-reference/input-output | |
// dfd.read_csv('https://gist.githubusercontent.com/egoing/43799f48b55b5eb2a8b37652eab72318/raw/3a207dd85d0b74968426e65ae2cee4cb1d4aef4f/lemon.csv') | |
// .then(function(data){// | |
// data.print(); | |
// }); | |
// d1.describe().print(); | |
// d1.plot('d_table').table(); | |
// d1.plot('d_line').line(); | |
// d1.print(); | |
// 데이터 선택 https://danfo.jsdata.org/getting-started#selection | |
// var s = new dfd.Series([20, 21, 22, 23]); | |
// console.log(s, d1['온도'], d1); // s와 d1['온도']는 Series이다. | |
// label of content https://danfo.jsdata.org/api-reference/dataframe/danfo.dataframe.loc | |
// d1.loc({columns:['온도', '판매량']}).print(); | |
// d1.loc({rows:[1,3]}).print(); | |
// d1.loc({columns:['온도', '판매량'], rows:[1,3]}).print(); | |
// 논리비교를 이용한 필터링 https://danfo.jsdata.org/api-reference/dataframe/danfo.dataframe.query | |
// d1 | |
// .query({ "column": "온도", "is": ">", "to": 20 }) | |
// .print(); | |
// d1 | |
// .query({ "column": "온도", "is": ">", "to": 20 }) | |
// .query({ "column": "판매량", "is": "<", "to": 46 }) | |
// .print(); | |
// 행 추가 | |
// var newRow = new dfd.DataFrame({'온도':[24,25], '요일':['월','월'], '판매량':[48,50]}); | |
// d1.append(newRow).print(); | |
// 열 추가 | |
// d1.addColumn({ "column": "비", "value": [1,0,1,0]}); | |
// d1.print(); | |
// 행삭제 | |
// d1.drop({axis:0, index:[0]}).print(); | |
// 열삭제 | |
// d1.drop({axis:1, columns:['온도']}).print(); | |
// to Array | |
// d1.to_json().then(function(json){ | |
// console.log(JSON.parse(json)) | |
// }); | |
// d1.tensor.print(); | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
온도 | 요일 | 판매량 | |
---|---|---|---|
20 | 월 | 40 | |
21 | 월 | 42 | |
22 | 월 | 44 | |
23 | 월 | 46 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment