Changing Custom .CSV Pre-Processing for HighMaps Map: Different .CSV format

I need to amend the following .CSV file parsing code in HighMaps to read from a different .CSV file format/structure:
Current .CSV format Parsing Code:

<script type='text/javascript'>//<![CDATA[
// NB ALL spreadsheet values must be converted to STRINGS/LEBELS before saving as .CSV format
// $.get('http://www.jcsweb.biz/mef/MapData/CO2pc.csv', function(csv) {
$.get('http://www.jcsweb.biz/mef/MapData/CO2pc_truncated.csv', function(csv) {
// Parse the CSV Data
/*Highcharts.data({ csv: data, switchRowsAndColumns: true,parsed: function () {console.log(this.columns);} });
*/
// Very simple and case-specific CSV string splitting
  function CSVtoArray(text) {return text.replace(/^"/, '').replace(/",$/, '').split('","');}
  csv = csv.split(/\n/); var countries = {},mapChart_2,countryChart_2,numRegex = /^[0-9\.]+$/,quoteRegex = /\"/g,
  categories = CSVtoArray(csv[1]).slice(4);
// Parse the CSV into arrays, one array each country
 $.each(csv.slice(2), function(j, line) {var row = CSVtoArray(line),data = row.slice(4);
 $.each(data, function(i, val) {val = val.replace(quoteRegex, '');
   if (numRegex.test(val)) {val = parseInt(val, 10);} else if (!val) {val = null;}data[i] = val; });
  countries[row[1]] = {name: row[0],code3: row[1],data: data}; });
// For each country, use the latest value for current population
 var data = [];
 for (var code3 in countries) {if (countries.hasOwnProperty(code3)) {var value = null,
   year,itemData = countries[code3].data,i = itemData.length;
   while (i--) {if (typeof itemData[i] === 'number') {value = itemData[i];year = categories[i];break; }}
  data.push({name: countries[code3].name,code3: code3,value: value,year: year}); }   }
// Add lower case codes to the data set for inclusion in the tooltip.pointFormat
  var mapData1 = Highcharts.geojson(Highcharts.maps['custom/world']);
  $.each(mapData1, function() {this.id = this.properties['hc-key']; // for Chart.get()
    this.flag_2 = this.id.replace('UK', 'GB').toLowerCase();  });
// Wrap point.select to get to the total selected points
 Highcharts.wrap(Highcharts.Point.prototype, 'select', function(proceed) {
 proceed.apply(this, Array.prototype.slice.call(arguments, 1));
 var points = mapChart_2.getSelectedPoints();
 if (points.length) {if (points.length === 1) {$('#info_2 #flag_2').attr('class', 'flag ' + points[0].flag_2);
  $('#info_2 h2').html(points[0].name);} else {
  $('#info_2 #flag_2').attr('class', 'flag'); $('#info_2 h2').html('Comparing countries');   }
  $('#info_2 .subheader').html('<h4>Historical Data</h4><small><em>Shift + Click on map to compare countries</em></small>');
 if (!countryChart_2) {countryChart_2 = Highcharts.chart('country-chart_2', {chart: {height: 250,spacingLeft: 0},
          credits: {enabled: false},
title: { text: null},   subtitle: { text: null}, xAxis: { tickPixelInterval: 50, crosshair: true},
yAxis: { title: null, opposite: true}, tooltip: { shared: true},
plotOptions: { series: { animation: { duration: 500 }, marker: { enabled: false }, threshold: 0, pointStart: parseInt(categories[0], 10) }}   });   }
 $.each(points, function(i) {
// Update
if (countryChart_2.series[i]) {/*$.each(countries[this.code3].data, function (pointI, value) {
  countryChart_2.series[i].points[pointI].update(value, false);});*/
  countryChart_2.series[i].update({name: this.name,data: countries[this.code3].data,
   type: points.length > 1 ? 'line' : 'area' }, false); }
   else {countryChart_2.addSeries({name: this.name,data: countries[this.code3].data,
         type: points.length > 1 ? 'line' : 'area'}, false); }  });
   while (countryChart_2.series.length > points.length) {
        countryChart_2.series[countryChart_2.series.length - 1].remove(false); }countryChart_2.redraw();  } else {
      $('#info_2 #flag_2').attr('class', '');$('#info_2 h2').html('');$('#info_2 .subheader').html('');
      if (countryChart_2) { countryChart_2 = countryChart_2.destroy();} } });
// Initiate the map chart
 mapChart_2 = Highcharts.mapChart('container_2', { title: {text: 'CO2 emissions metric tons per capita'},
  subtitle: { text: 'Source: <a href="http://data.worldbank.org/indicator/EN.ATM.CO2E.PC/countries/1W?display=default">The World Bank</a>' },
    mapNavigation: {enabled: true, buttonOptions: {verticalAlign: 'bottom'} },
    colorAxis: {type: 'linear',endOnTick: false,startOnTick: false,min: -10},
    	tooltip: {footerFormat: '<span style="font-size: 10px">(Click for details)</span>'},
    series: [{data: data,mapData: mapData1,
      joinBy: ['iso-a3', 'code3'],name: 'Current data',allowPointSelect: true,cursor: 'pointer',
      states: {select: {color: '#a4edba',borderColor: 'black',dashStyle: 'shortdot'} } }]});
// Pre-select a country
   mapChart_2.get('us').select(); });
// tell the embed parent frame the height of the content
if (window.parent && window.parent.parent) {window.parent.parent.postMessage(["resultsFrame", {
    height: document.body.getBoundingClientRect().height,slug: "j0fkvah0"}], "*")}
//]]>
</script>

The above js parses the existing .CSV file format/structure below where ALL entries are strings (including values)

"Data Source","World Development Indicators",
"Country Name","Country Code","Indicator Name","Indicator Code","1960","1961","1962","1963","1964","1965","1966","1967","1968","1969","1970","1971","1972","1973","1974","1975","1976","1977","1978","1979","1980","1981","1982","1983","1984","1985","1986","1987","1988","1989","1990","1991","1992","1993","1994","1995","1996","1997","1998","1999","2000","2001","2002","2003","2004","2005","2006","2007","2008","2009","2010","2011","2012","2013","2014"
"Afghanistan","AFG","CO2 emissions metric tons per capita","EN.ATM.CO2E.PC","0.04606788","0.05361494","0.07378134","0.07425137","0.08631654","0.10149861","0.10767397","0.12378238","0.11554738","0.08686282","0.15035855","0.16611485","0.13082014","0.13633995","0.15572512","0.16902708","0.15489503","0.18311831","0.16334697","0.16867349","0.13323027","0.15263974","0.16587912","0.20546270","0.23764295","0.30173420","0.27472970","0.27556031","0.25207916","0.23913121","0.21666094","0.19067040","0.10137476","0.09078220","0.08156608","0.07411605","0.06733328","0.06079767","0.05625850","0.04314476","0.03927212","0.03107754","0.04112923","0.04561884","0.04041528","0.05440397","0.06552475","0.08785764","0.15896156","0.24907353","0.30293639","0.42526211","0.68808361","0.69318341EN.ATM.CO2E.PC","1.25819493","1.37418605","1.43995596","1.18168114","1.11174196","1.16609904","1.33305547","1.36374630","1.51955128","1.55896757","1.75323991","1.98949792","2.51591440","2.30389742","1.84900669","1.91063364","2.01358456","2.27587639","2.53062504","2.89820852","1.93505831","2.69302391","2.62485679","2.68323992","2.69429137","2.65801538","2.66535622","2.41406082","2.33159853","2.78324308","1.61562396","1.31221260","0.77472491","0.72379029","0.60020371","0.65453EN.ATM.CO2E.PC","1.25819493","1.37418605","1.43995596","1.18168114","1.11174196","1.16609904","1.33305547","1.36374630","1.51955128","1.55896757","1.75323991","1.98949792","2.51591440","2.30389742","1.84900669","1.91063364","2.01358456","2.27587639","2.53062504","2.89820852","1.93505831","2.69302391","2.62485679","2.68323992","2.69429137","2.65801538","2.66535622","2.41406082","2.33159853","2.78324308","1.61562396","1.31221260","0.77472491","0.72379029","0.60020371","0.65453713","0.63662531","0.49036506","0.56027144","0.96016441","0.97817468","1.05330418","1.22954071","1.41269720","1.37621274","1.41249821","1.30257637","1.32233486","1.48431114","1.49560020","1.57857358","1.80397242","1.62472196","1.66218483EN.ATM.CO2E.PC","0.55376358","0.53180999","0.48495366","0.45282446","0.45956892","0.52244853","0.64948061","0.63211843","0.65926255","0.79720564","1.03608267","1.24789829","1.84362371","2.42418239","1.96382994","1.91699426","2.27867110","2.36808210","3.43337072","2.43173222","3.43987656","2.32850298","1.90855724","2.47900900","3.24762923","3.22549764","3.28197415","3.51707377","3.41372649","3.16921315","3.00791101","3.01998895","2.97599750","2.96173908","3.04988426","3.29866EN.ATM.CO2E.PC","0.55376358","0.53180999","0.48495366","0.45282446","0.45956892","0.52244853","0.64948061","0.63211843","0.65926255","0.79720564","1.03608267","1.24789829","1.84362371","2.42418239","1.96382994","1.91699426","2.27867110","2.36808210","3.43337072","2.43173222","3.43987656","2.32850298","1.90855724","2.47900900","3.24762923","3.22549764","3.28197415","3.51707377","3.41372649","3.16921315","3.00791101","3.01998895","2.97599750","2.96173908","3.04988426","3.29866722","3.30246252","2.95087835","3.52969940","2.99411874","2.81977801","2.66832780","2.84002791","2.85641005","2.72701714","3.22015456","2.99754697","3.19586459","3.16852449","3.43012896","3.30716434","3.30055779","3.47194993","3.51478009EN.ATM.CO2E.PC","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""
"Andorra","ADO","CO2 emissions metric tons per capita","EN.ATM.CO2E.PC","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","6.37449494","6.61635377","7.14569660","7.57644628","8.00143389","8.01818071","7.73765678","7.48409481","7.1591404EN.ATM.CO2E.PC","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","",""
"Andorra","ADO","CO2 emissions metric tons per capita","EN.ATM.CO2E.PC","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","6.37449494","6.61635377","7.14569660","7.57644628","8.00143389","8.01818071","7.73765678","7.48409481","7.15914045","7.20882852","7.08812775","6.55347655","6.35086831","6.29612456","6.04917285","6.12477049","5.96868547","6.19519391","6.47384786

but I need to plot Highmaps from this “transposed” .CSV format where ONLY genuine strings have surrounding double quotes:

"Date","UR_u","UR_c","UR_m","UR_ar","UR_br","UR_j","UR_a","UR_sk","UR_th","UR_ma","UR_si","UR_hk","UR_ta","UR_in","UR_ph","UR_ch","UR_id","UR_g","UR_f","UR_i","UR_e","UR_n","UR_b","UR_os","UR_fi","UR_ir","UR_po","UR_lx","UR_gr","UR_s","UR_k","UR_de","UR_sw","UR_no","UR_tu","UR_ru","UR_sa"
2016,0.003963,0.006084,0.002111,-0.000197,-0.000318,0.000568,0.014578,0.000342,0.016408,7.2E-005,0,-8.3E-005,0.001574,-3.4E-005,0.005911,0,-0.000151,-0.000878,-0.000366,3.4E-005,0.001051,0.000209,0.00136,0.000409,0.000657,0.002073,0.000728,-0.00051,-0.00092,0.001234,-5.2E-005,0.000422,0.000746,0.000473,0.003899,-0.00074,-0.003275
2017,0.007091,0.014456,0.016454,-0.000141,-0.000727,0.002533,0.007922,0.00416,0.02304,-0.000644,0,-0.002631,0.00279,-0.000318,0.006397,0,0.000508,0.004996,0.002536,0.002198,0.013585,0.00243,0.007072,0.003439,0.003466,0.018666,0.012353,-0.00208,-0.001192,0.00597,0.002485,0.00055,0.005571,0.000358,0.014366,-0.002562,0.000922
2018,0.003396,0.004885,0.020803,-0.000896,-0.002011,0.002868,-0.004984,0.007556,0.013071,-0.00349,0,-0.008229,-0.003577,-0.000471,-0.006503,0,0.002464,0.001911,0.002903,0.002459,0.013438,0.005171,0.006102,0.004132,0.001461,-0.004236,0.013504,-0.004566,-0.002544,0.003158,0.005898,-0.003126,0.009035,-0.002845,0.007386,-0.007133,-0.008462
2019,-7.3E-005,-0.004131,0.016334,-0.002386,-0.002886,0.003769,-0.007871,0.009056,0.002467,-0.006999,0,-0.012555,-0.00595,-0.000781,-0.015681,0,0.000549,-0.000681,0.000377,0.000997,0.003939,0.004807,0.00159,0.003421,0.000488,-0.025806,0.005995,-0.007049,-0.00417,-0.000669,0.008297,-0.007711,0.013387,-0.007608,0.001228,-0.011523,-0.01018
2020,-0.002916,-0.007675,0.006434,-0.002903,-0.003013,0.004183,-0.001211,0.00766,0,-0.010585,0,-0.012622,-0.008734,-0.001129,-0.018544,0,-0.001433,-0.002769,-0.003188,-0.000945,-0.005789,0.000582,-0.002897,0.000583,-0.000881,-0.034365,-0.003547,-0.007972,-0.005152,-0.004845,0.007308,-0.012359,0.017128,-0.012974,-0.000445,-0.01392,-0.010079
2021,-0.005252,-0.007246,-0.004995,-0.003066,-0.002773,0.003507,0.00565,0.003141,0,-0.013643,0,-0.008357,-0.009671,-0.001418,-0.015501,0,-0.0023,-0.005009,-0.006646,-0.003166,-0.011756,-0.005886,-0.005637,-0.003047,-0.002558,-0.035114,-0.012164,-0.006735,-0.00637,-0.006396,0.000398,-0.015112,0.018846,-0.017876,-0.000725,-0.015518,-0.009269
2022,-0.006996,-0.004257,-0.014488,-0.003861,-0.002636,0.002293,0.007397,-0.003729,0,-0.015996,0,-0.002105,-0.008876,-0.001629,-0.0109,0,-0.002813,-0.00676,-0.009379,-0.005273,-0.013595,-0.012165,-0.006342,-0.00629,-0.003837,-0.032258,-0.018052,-0.004082,-0.007686,-0.005397,-0.009233,-0.015947,0.019036,-0.022105,-0.001163,-0.018211,-0.008713
2023,-0.008235,0.001564,-0.019781,-0.004884,-0.002678,0.001277,0.004666,-0.011153,0,-0.017965,0,-0.000255,-0.008008,-0.001786,-0.010282,0,-0.003029,-0.007004,-0.011273,-0.007159,-0.013443,-0.016161,-0.005953,-0.008617,-0.004936,-0.027747,-0.021197,-0.001443,-0.008621,-0.003529,-0.015888,-0.01539,0.018461,-0.025824,-0.001556,-0.022663,-0.008853
2024,-0.008362,0.005594,-0.019543,-0.005476,-0.002031,0.001105,0.001502,-0.016576,0,-0.019403,0,-0.007521,-0.006252,-0.001903,-0.012848,0,-0.003495,-0.007536,-0.012277,-0.008813,-0.011955,-0.017008,-0.005229,-0.009061,-0.00405,-0.020755,-0.021284,0.000109,-0.0087,-0.002873,-0.016037,-0.014244,0.018334,-0.030356,-0.001392,-0.028217,-0.009569
2025,-0.012268,-0.04762,-0.023108,-0.005948,0,-0.003144,0.000187,-0.028742,0,-0.027244,2E-006,-0.042328,-0.042746,-0.002227,-0.037978,0,-0.007816,-0.038498,-0.014515,-0.011111,-0.027224,-0.018683,-0.014418,-0.011774,-0.018195,-0.06945,-0.027251,-0.002212,-0.009551,-0.01502,-0.008864,-0.018937,0.003999,-0.048293,-0.007799,-0.040307,-0.010436

Above CSV Structure Explained:
First row - are labels; UR = Unemployment Rate + country suffixes “_u” = US, “_c” = “Canada”, _m = “Mexico” etc
Subsequent rows - are time series data values relating to the years in Col1

The country suffixes will also then need to be “lookedup”/replaced using the following ASCII file contents to show Country Name instead of UR_?:

_u	United States
_j	Japan
_g	Germany
_f	France
_i	Italy
_c	Canada
_k	United Kingdom
_e	Spain
_n	Netherland
_b	Belgium
_s	Sweden
_sw	Switzerland
_sk	Korea
_a	Australia
_m	Mexico
_ch	China
_de	Denmark
_os	Austria
_no	Norway
_fi	Finland
_ir	Ireland
_po	Portugal
_gr	Greece
_lx	Luxembourg
_ic	Iceland
_nz	New Zealand
_tu	Turkey
_cz	Czech Republic
_hu	Hungary
_pl	Poland
_sl	Slovak Republic
_da	Dynamic Asia: 
_th	Thailand
_ma	Malaysia
_si	Singapore
_hk	Hong Kong
_ta	Taiwan
_in	Indonesia
_ph	Philippines
_ar	Argentina
_br	Brazil
_ru	Russia
_sa	South Africa
_id	India
_ee	Eastern Europe
_am	Africa & Middle East
_la	Latin America
_rw	Rest Of The World

Can anyone assist with amending the Current .CSV format Parsing Code to read from the “transposed” .CSV format with Country Name lookup/replace ?
Appreciate any assistance/pointers

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.