Skip to content

Instantly share code, notes, and snippets.

@DimsumPanda
Last active October 25, 2015 15:01
Show Gist options
  • Save DimsumPanda/1bdcbc60306d67981fde to your computer and use it in GitHub Desktop.
Save DimsumPanda/1bdcbc60306d67981fde to your computer and use it in GitHub Desktop.
Week 9: JS homework
Country Year Meningitis_encephalitis Respiratory_infections Sepsis Pertussis Malaria Measles HIV_Aids Diarrhoeal_diseases Asphyxia_trauma
Angola Year 2013 5461 26392 7199 897 19405 627 1778 22465 14245
Angola Year 2012 5747 26910 7149 893 19692 1278 1769 23655 14150
Angola Year 2000 9282 25989 4172 931 21138 1103 1179 27209 9800
Angola Year 2001 9452 26463 4784 918 21232 3889 1276 27064 9715
Angola Year 2011 6107 27282 7044 911 21331 573 1704 24567 13909
Angola Year 2002 9628 27141 5269 931 21793 5054 1373 26969 10068
Angola Year 2006 10465 30754 6064 1047 22022 602 1590 27001 12620
Angola Year 2003 9840 28190 5219 964 22530 1786 1466 27015 11186
Angola Year 2005 10242 29865 5742 1014 23066 297 1601 26962 12292
Angola Year 2004 9987 28764 5685 976 23161 24 1545 26830 11386
Angola Year 2007 6681 27597 6914 943 23597 333 1594 28242 12913
Angola Year 2010 5899 26780 7363 906 23827 338 1629 25156 13731
Angola Year 2008 6658 27658 7095 935 24441 328 1605 27199 13333
Angola Year 2009 6851 27898 7453 973 24858 976 1610 25887 13953
Congo Year 2013 9101 49598 16965 3102 47519 15453 4487 33730 32994
Congo Year 2012 9464 50424 16477 3049 48443 15191 4411 35679 32653
Congo Year 2011 9517 50487 15822 2990 50175 31815 4673 37069 33651
Congo Year 2010 10559 51027 17331 3123 51128 5082 4837 37904 31325
Congo Year 2009 10101 50916 18086 2936 52037 5166 4985 40063 32521
Congo Year 2008 14461 54789 16769 2996 55752 5957 5154 38179 31857
Congo Year 2007 14036 52394 16399 2923 65794 11342 5310 37671 31236
Congo Year 2000 14917 49542 10926 2951 69177 39600 5135 45561 26571
Congo Year 2006 14259 52196 15473 3007 69414 17086 5518 38939 31130
Congo Year 2005 14634 52396 15521 3005 71000 39181 5597 40592 30835
Congo Year 2001 15393 51350 10258 3052 71367 38386 5305 46001 27774
Congo Year 2004 15031 52626 15097 3009 72224 54739 5601 42374 30474
Congo Year 2002 15578 52583 12961 3066 72603 51468 5454 45553 29659
Congo Year 2003 15416 52777 14298 3091 72874 35548 5551 44223 29881
Zambia Year 2013 1082 7550 3230 659 8328 564 3044 4563 6251
Zambia Year 2012 1110 7537 3131 632 8334 736 2921 4729 6037
Zambia Year 2011 1086 7223 3124 597 9155 1740 4776 4773 5855
Zambia Year 2010 1179 7590 3177 569 7969 2223 6335 5317 5771
Zambia Year 2009 1170 7760 3061 529 7349 146 6844 5850 5646
Zambia Year 2008 1237 7684 2966 530 8024 73 7940 5929 5484
Zambia Year 2007 1315 7666 2908 534 8616 248 8911 6059 5360
Zambia Year 2006 1339 7644 2926 522 9472 224 9808 6301 5335
Zambia Year 2005 1358 7593 2968 510 11000 102 10381 6516 5375
Zambia Year 2004 1398 7619 3019 496 12630 6 10928 6833 5414
Zambia Year 2003 2381 8996 3089 488 12574 716 11099 7096 5505
Zambia Year 2002 2610 9476 3159 478 13239 2911 11104 7852 5609
Zambia Year 2001 2811 9853 3170 466 13914 2129 11056 8541 5759
Zambia Year 2000 2923 9952 3042 455 14402 3616 10944 9000 5739
Namibia Year 2013 42 428 208 69 1 114 197 217 351
Namibia Year 2012 45 443 204 69 1 68 196 230 353
Namibia Year 2011 49 461 200 69 5 83 284 249 351
Namibia Year 2010 52 472 201 67 3 106 442 268 357
Namibia Year 2009 81 538 199 66 7 149 608 260 362
Namibia Year 2008 85 544 203 65 16 40 769 275 363
Namibia Year 2007 89 549 209 65 23 39 918 290 359
Namibia Year 2006 88 531 207 62 124 35 1082 291 373
Namibia Year 2005 94 544 212 64 111 27 1324 315 370
Namibia Year 2004 92 519 213 61 219 17 1508 311 376
Namibia Year 2003 100 559 214 67 112 68 1494 347 388
Namibia Year 2002 101 568 214 66 123 79 1431 359 415
Namibia Year 2001 96 550 216 63 222 19 1334 350 448
Namibia Year 2000 99 569 215 65 145 24 1206 373 435
Botswana Year 2013 24 282 181 8 1 36 124 139 296
Botswana Year 2012 26 297 185 9 1 25 126 152 304
Botswana Year 2011 27 306 195 10 1 28 209 163 321
Botswana Year 2010 48 361 199 10 5 42 242 159 326
Botswana Year 2009 50 366 204 10 6 29 340 168 334
Botswana Year 2008 52 366 197 8 5 16 418 176 328
Botswana Year 2007 52 366 193 8 3 13 430 182 323
Botswana Year 2006 52 361 185 8 13 8 496 185 313
Botswana Year 2005 56 364 174 9 3 24 736 198 301
Botswana Year 2004 61 367 163 8 17 27 1181 215 292
Botswana Year 2003 67 372 154 9 10 34 1680 236 288
Botswana Year 2002 67 363 152 9 10 43 1947 239 290
Botswana Year 2001 63 343 150 8 30 84 2049 229 290
Botswana Year 2000 56 314 152 8 60 366 2051 210 292
Mozambique Year 2013 1673 11669 5632 1061 14685 0 5468 7000 9272
Mozambique Year 2012 1801 12092 5575 1040 15203 214 5361 7538 9322
Mozambique Year 2011 1887 12187 5663 1024 17293 867 7440 7963 9474
Mozambique Year 2010 1943 12123 5766 1023 19800 1504 8308 8189 9648
Mozambique Year 2009 2045 12446 5958 1019 20929 157 8550 8747 9932
Mozambique Year 2008 3227 14399 6172 1021 21071 500 9468 9063 10236
Mozambique Year 2007 3357 14572 6384 1021 23763 424 10668 9546 10603
Mozambique Year 2006 3546 14909 6570 1009 26032 115 12097 10183 10973
Mozambique Year 2005 3719 15232 6594 990 27154 8257 11671 10824 11146
Mozambique Year 2004 3945 15612 6054 959 27672 6166 10892 11622 10869
Mozambique Year 2003 4135 15889 5910 918 28118 6054 9903 12334 10768
Mozambique Year 2002 4284 15999 5840 907 28815 4754 8763 12955 10652
Mozambique Year 2001 4464 16197 5829 879 29373 4730 7529 13667 10556
Mozambique Year 2000 4742 16699 5929 853 30354 4841 6313 14683 10645
Tanzania Year 2013 1376 14263 7448 1911 9272 259 5526 7087 12984
Tanzania Year 2012 1459 14777 7536 1890 9657 134 5464 7692 13198
Tanzania Year 2011 1589 15313 7691 1899 10166 346 6796 8334 13502
Tanzania Year 2010 1637 15235 7730 1855 12427 336 9186 8727 13695
Tanzania Year 2009 1704 14918 7939 1872 16927 520 11386 8734 14329
Tanzania Year 2008 2865 17310 7781 1806 17518 802 12781 8863 14589
Tanzania Year 2007 3233 18457 7943 1754 17589 1190 14335 10051 14918
Tanzania Year 2006 3472 18899 8180 1642 20133 255 15601 10856 15311
Tanzania Year 2005 3797 19662 8409 1592 22146 506 16352 11945 15639
Tanzania Year 2004 4197 20635 8595 1511 24071 635 16988 13274 15977
Tanzania Year 2003 4582 21445 8799 1477 27055 830 17325 14581 16251
Tanzania Year 2002 5106 22701 8861 1470 29298 1258 17568 16352 16562
Tanzania Year 2001 5697 24029 9112 1445 31408 2388 17686 18352 16595
Tanzania Year 2000 6301 25386 9032 1450 33425 2980 17658 20467 16889
Kenya Year 2013 2348 18576 6843 1619 4637 238 4656 10515 14726
Kenya Year 2012 2469 19081 7072 1606 4770 312 4617 11247 14799
Kenya Year 2011 2505 19387 7424 1556 5118 341 5004 12063 14836
Kenya Year 2010 2738 20007 7900 1577 5272 189 6642 12850 14894
Kenya Year 2009 2842 20366 7978 1561 5422 476 8202 13650 15333
Kenya Year 2008 2931 20621 7980 1549 5642 490 9386 14420 15461
Kenya Year 2007 3160 21136 7797 1549 5564 569 11512 15301 15494
Kenya Year 2006 3263 21210 7801 1523 6027 545 13044 15932 15399
Kenya Year 2005 3368 21072 7543 1523 7373 414 14589 16228 15518
Kenya Year 2004 3451 20880 7537 1493 7963 197 15650 16555 15165
Kenya Year 2003 3494 20776 7443 1444 7903 10 16193 17077 14893
Kenya Year 2002 3265 20197 7451 1348 7893 773 16505 17668 14521
Kenya Year 2001 5017 22273 7248 1332 7115 1300 16648 16523 13733
Kenya Year 2000 4984 21867 6959 1272 7010 1618 16597 16757 13405
Gabon Year 2013 37 354 213 58 540 14 64 183 355
Gabon Year 2012 38 354 208 57 548 36 63 193 344
Gabon Year 2011 40 358 208 58 565 34 105 199 350
Gabon Year 2010 46 380 209 59 530 31 140 219 351
Gabon Year 2009 71 449 212 55 423 28 168 235 361
Gabon Year 2008 75 458 212 52 399 12 200 249 365
Gabon Year 2007 74 445 205 51 462 40 239 252 361
Gabon Year 2006 72 419 195 58 545 34 265 247 337
Gabon Year 2005 69 398 189 57 611 9 274 242 331
Gabon Year 2004 68 391 187 56 635 100 278 245 331
Gabon Year 2003 69 388 180 55 642 204 275 252 324
Gabon Year 2002 70 387 193 55 643 131 265 259 333
Gabon Year 2001 70 385 162 53 640 248 249 265 312
Gabon Year 2000 70 385 156 51 642 111 229 273 309
Cameroon Year 2013 2067 12718 4212 843 9261 218 2142 8497 8361
Cameroon Year 2012 2195 13028 4176 831 9416 377 2112 8960 8343
Cameroon Year 2011 2206 12691 3974 832 11965 293 2431 8986 8131
Cameroon Year 2010 2104 12104 4289 814 15034 123 2868 8819 8259
Cameroon Year 2009 2276 12536 4268 819 15095 286 3455 9448 8314
Cameroon Year 2008 3400 14505 4361 798 13564 162 3771 9569 7998
Cameroon Year 2007 3520 14666 4303 798 14171 227 4020 10069 8020
Cameroon Year 2006 3569 14514 4362 800 15427 409 4161 10373 7774
Cameroon Year 2005 3599 14337 4206 798 16822 519 4260 10638 7724
Cameroon Year 2004 3682 14341 4042 806 17712 362 4259 11072 7663
Cameroon Year 2003 3820 14510 3953 797 18017 150 4230 11660 7660
Cameroon Year 2002 3977 14698 3716 798 18374 222 4107 12324 7558
Cameroon Year 2001 4125 14835 3326 791 18601 7031 3888 12977 7296
Cameroon Year 2000 4246 14972 3326 781 18817 4663 3579 13588 7322
Central African Republic Year 2013 755 3175 911 197 5459 0 664 2002 2360
Central African Republic Year 2012 699 3045 1049 192 5581 195 647 2090 2147
Central African Republic Year 2011 718 3087 1129 187 5683 802 776 2184 2198
Central African Republic Year 2010 742 3118 1153 185 5743 135 921 2270 2207
Central African Republic Year 2009 760 3136 1160 185 5847 34 1052 2332 2254
Central African Republic Year 2008 921 3348 1156 183 5683 175 1187 2373 2241
Central African Republic Year 2007 943 3339 939 182 5666 114 1316 2474 2081
Central African Republic Year 2006 949 3331 921 181 5718 64 1449 2541 2066
Central African Republic Year 2005 935 3276 894 180 5907 785 1570 2562 2056
Central African Republic Year 2004 922 3216 774 181 6046 1476 1631 2585 1975
Central African Republic Year 2003 917 3193 743 186 6082 955 1657 2636 1952
Central African Republic Year 2002 914 3177 732 187 6073 1314 1645 2692 1947
Central African Republic Year 2001 905 3143 752 188 6024 2186 1605 2735 1949
Central African Republic Year 2000 891 3100 747 186 5964 2491 1539 2765 1954
Uganda Year 2013 2075 15454 6403 1735 12935 550 7382 8383 10680
Uganda Year 2012 2201 15911 6385 1695 13356 500 7213 9024 10702
Uganda Year 2011 2313 16212 6586 1637 14344 355 9470 9790 10817
Uganda Year 2010 2486 16733 6466 1624 16216 172 9853 10518 11395
Uganda Year 2009 2631 17052 6774 1586 18461 742 9823 11189 11540
Uganda Year 2008 2939 17783 6695 1614 20556 685 9841 12052 11725
Uganda Year 2007 3141 18353 6889 1561 22631 612 9930 13148 12015
Uganda Year 2006 3536 19216 6860 1587 24896 340 9694 14200 12253
Uganda Year 2005 3782 19670 7180 1539 27691 105 9409 15309 12234
Uganda Year 2004 4131 20409 7095 1513 29455 31 9427 16681 12362
Uganda Year 2003 4853 21683 6946 1483 30235 10509 9690 17967 12341
Uganda Year 2002 5510 22717 6863 1450 30682 14138 10098 19139 12400
Uganda Year 2001 6447 23927 6539 1416 30414 9449 10631 19887 12238
Uganda Year 2000 6614 23825 6389 1384 30264 12943 11319 20691 11976
Nigeria Year 2013 24987 120199 41218 9539 166102 4625 24647 76938 84188
Nigeria Year 2012 29969 127745 39068 9281 164702 4660 23981 79453 81893
Nigeria Year 2011 31982 131691 34962 8885 166599 16306 25194 82867 88220
Nigeria Year 2010 32045 129541 39813 8367 180694 8134 26927 83863 88298
Nigeria Year 2009 31193 123705 41418 7927 202337 1653 27451 82688 84847
Nigeria Year 2008 30885 120767 38510 8124 222263 10822 28321 83354 85843
Nigeria Year 2007 31384 120575 36049 8304 232256 5511 28767 86285 86422
Nigeria Year 2006 31989 120416 35637 8215 238509 17257 29095 89331 85400
Nigeria Year 2005 32968 121378 34611 8117 241102 83182 28862 93514 84467
Nigeria Year 2004 34020 122591 33363 8001 243207 39144 27706 98038 83609
Nigeria Year 2003 35105 123796 32448 7869 244883 107428 26139 102796 82397
Nigeria Year 2002 36028 124582 31007 7728 244708 45910 24259 107088 81806
Nigeria Year 2001 36825 124719 30455 7453 243805 125379 22166 110944 80083
Nigeria Year 2000 37609 124790 29564 7222 243379 159344 19988 114935 78077
Malawi Year 2013 640 5465 2632 601 5927 314 5056 3003 4320
Malawi Year 2012 661 5719 2760 613 6322 374 5157 3335 4473
Malawi Year 2011 747 6158 2910 623 6213 271 6841 3823 4759
Malawi Year 2010 838 6457 3009 629 6812 1317 7925 4181 4964
Malawi Year 2009 876 6514 3060 614 8260 94 8438 4411 5121
Malawi Year 2008 986 6883 3133 594 8384 418 9280 4920 5207
Malawi Year 2007 1134 7324 3109 576 8314 299 10158 5512 5281
Malawi Year 2006 1123 7409 3103 528 9485 172 10698 6067 5206
Malawi Year 2005 1272 7696 3078 519 10536 859 11024 6581 5113
Malawi Year 2004 1469 8251 3091 510 11027 745 11110 7414 5145
Malawi Year 2003 1685 8787 3099 504 12357 602 11081 8239 5271
Malawi Year 2002 2095 9455 2970 524 14295 438 10992 8937 5365
Malawi Year 2001 3209 10961 3288 465 15047 244 10881 9507 5406
Malawi Year 2000 3574 11694 3185 477 16288 114 10735 10694 5548
Ethiopia Year 2013 4516 34565 15241 3762 5748 4541 4588 18534 29664
Ethiopia Year 2012 4961 36242 15540 3709 6008 4085 4524 20189 29541
Ethiopia Year 2011 5396 37836 17627 3620 6137 1837 6060 21677 30864
Ethiopia Year 2010 5950 39843 17790 3641 6946 7260 7330 23771 31969
Ethiopia Year 2009 6821 42914 18251 3741 6549 13815 8598 26582 33169
Ethiopia Year 2008 7847 46382 18403 3739 6895 9038 9970 30122 34272
Ethiopia Year 2007 8934 49596 18903 3893 10061 3629 11554 33606 35566
Ethiopia Year 2006 11819 56051 19234 3950 13669 19031 13000 36018 36829
Ethiopia Year 2005 13344 60115 19540 4003 16518 13878 14212 40991 38021
Ethiopia Year 2004 15051 64609 19560 4088 17975 17861 15024 46348 39607
Ethiopia Year 2003 16791 68857 19294 4254 19253 20414 15543 52028 40414
Ethiopia Year 2002 18437 72689 19089 4195 20382 17334 15743 57589 41243
Ethiopia Year 2001 19810 75475 18264 4061 21246 7351 15616 62503 41441
Ethiopia Year 2000 20710 76786 17273 4062 21660 20634 15126 66157 41262
Rwanda Year 2013 375 3850 1597 417 949 131 329 2028 2873
Rwanda Year 2012 423 4197 1725 435 1033 126 343 2317 3114
Rwanda Year 2011 481 4544 1838 444 982 103 474 2639 3321
Rwanda Year 2010 528 4748 1931 434 929 60 702 2913 3488
Rwanda Year 2009 569 4856 1915 402 1073 123 786 3161 3497
Rwanda Year 2008 598 4812 1761 350 1195 99 924 3335 3401
Rwanda Year 2007 638 4763 1545 295 1229 47 1166 3555 3139
Rwanda Year 2006 711 4940 1481 256 1433 165 1455 4022 2898
Rwanda Year 2005 920 5756 1461 254 1978 98 1711 5014 3077
Rwanda Year 2004 1264 7116 1722 287 2563 22 2015 6536 3726
Rwanda Year 2003 1669 9157 2300 341 3383 394 2291 9130 4863
Rwanda Year 2002 2421 11960 2920 422 4307 609 2411 12386 6326
Rwanda Year 2001 4785 15817 3210 493 4576 461 2512 14008 7314
Rwanda Year 2000 5196 16468 3689 477 4725 588 2570 15254 7682
Burundi Year 2013 862 6483 2474 420 1790 210 462 4094 4173
Burundi Year 2012 897 6579 2505 411 1817 104 453 4331 4149
Burundi Year 2011 928 6647 2398 400 1898 79 515 4554 4234
Burundi Year 2010 945 6637 2538 389 2127 79 593 4708 4292
Burundi Year 2009 976 6604 2569 378 2391 149 690 4852 4226
Burundi Year 2008 1017 6575 2402 365 2608 120 762 5045 4061
Burundi Year 2007 993 6499 2346 340 2861 53 845 5295 4091
Burundi Year 2006 1065 6484 2183 333 3114 180 925 5424 3923
Burundi Year 2005 1141 6571 2070 326 3265 129 1045 5656 3993
Burundi Year 2004 1220 6641 2053 317 3357 95 1192 5935 3844
Burundi Year 2003 1940 7489 1998 306 3155 18 1324 5733 3721
Burundi Year 2002 2022 7575 1930 299 3213 197 1446 6062 3635
Burundi Year 2001 2113 7690 1799 292 3281 2415 1558 6429 3514
Burundi Year 2000 2201 7819 1730 290 3355 2126 1651 6806 3467
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<h2>Look in the console.</h2>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script>
<script>
d3.csv("deaths_04yearsold_excerpt.csv", function(error, data) {
if (error) {
console.log(error);
}
console.log(data);
var illnesses = d3.keys(data[0]).filter(function (key) {
return (key !== "Country") && (key !== "Year")
// TODO: how do you get all the keys that are not country or year?
});
console.log("keys", illnesses);
data.forEach(function(d) {
var sum = 0;
d.illnesses = illnesses.map(function(name) {
return {
name: name,
sum: sum += +d[name]};
});
// TODO: how would you use the illnesses list to get the total for each row's illnesses? use a forEach.
d.total = d.illnesses[d.illnesses.length - 1].sum;
});
console.log("totals", data);
var countryNames = data.map(function(d){
return d.Country;});//TODO: // How would you use a map to get the country names out of the original data file?
countryNames.sort(d3.ascending);
//TODO: sort them alphabetically)
console.log(countryNames);
var dateFormat = d3.time.format("Year %Y");
var outputFormat = d3.time.format("%Y");
var nestByCountry = d3.nest()
.key(function(d) {return d.Country;})
.sortKeys(d3.ascending)
.entries(data);//TODO: what goes in here?);
console.log("nest By country", nestByCountry[0]);
var nestByYear = d3.nest()
.key(function(d) {
return outputFormat(dateFormat.parse(d.Year));})
.sortKeys(function(a,b) {
console.log(a, b);
return a - b;
// TODO: How would you sort these? think about using your date formats, and check what a and b are.
})
.entries(data);
console.log("nest By Year", nestByYear[0]);
// var years = data.map(function(d){
// return outputFormat(dateFormat.parse(d.Year));
// });// TODO: use a map function on the nestByYear to get the years as strings in an array.
var years = nestByYear.map(function(d){
return d.key;
}); //return the keys, which are the years.
console.log(years);
var maxMalariaFor2013 = d3.max(nestByYear[13].values, function(d) {
return +d.Malaria;
});
//TODO: find the max malaria in 2013 using the nestByYear results, using maps, filters, d3.max, d3.keys, d3.values, etc. There are several ways.
// Don't forget the little plus sign!!! Otherwise, the answer doesn't return the right maximum number.
// var maxMalariaFor2013 = d3.max(nestByYear, function(d) {
// return d3.max(d.values, function(d) {
// return d.Malaria;
// })
// });
// var maxMalariaFor2013 = nestByYear[13]
console.log("Greatest incidence of Malaria in 2013: ", maxMalariaFor2013);
var nestByCountryYear = d3.nest()
.key(function(d) {
return d.Country;
})
.sortKeys(d3.ascending)
.key(function(d) {
return outputFormat(dateFormat.parse(d.Year));
})
.sortKeys(function(a,b) {
return a - b;})
// TODO: nest by country, then by year.
.entries(data);
console.log("by country then year", nestByCountryYear[0]);
});
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment