Can this code be refactored? It looks really ugly to me, but working with objects - as opposed to arrays - always results in ugly code, at least for me. Ideas welcome - thanks!
Data:
Output required:
I need each of the properties of each of the objects (i.e. rows from data above) to be converted into numbers. All except the first property which I need to remain a text value.
d3.csv("data/Book2.csv").then(function(data) {
console.log(data);
data.forEach(function(d) {
//Update all values to be numbers instead of string
for (let property in d) {
let allowableKeys =
d[property] !== "Number of Agents" &&
d[property] !== "Number of Active BB Agents" &&
d[property] !== "Number of Accounts" &&
d[property] !== "Active Accounts" &&
d[property] !== "Deposits as of date (Rs. in millions )" &&
d[property] !== "Number of transactions during the quarter" &&
d[property] !==
"Value of transactions during the quarter(Rs. in millions)" &&
d[property] !== "Average Size of transaction (in Rupees)" &&
d[property] !== "Average number of transaction per day";
if (d.hasOwnProperty(property) && allowableKeys) {
d[property] = parseFloat(d[property].replace(/,/g, ""));
}
}
dataNumAgent = data.filter(d => d.Indicator === "Number of Agents");
dataNumActAgent = data.filter(
d => d.Indicator === "Number of Active BB Agents"
);
});
//x-scale:
// let xScale = d3.scaleTime.domain().range();
});