I’m trying to convert a CSV file with numbers, strings, and currency data into something that I can work with. I’m having a hard time understanding how I should do this. I looked around in the documentation, but couldn’t really grasp the concepts there.
And here is the function -
d3.csvParse(await FileAttachment(“bloomberg_billionaires.csv”).text(), d3.autoType)
autotype helps me with converting the rank to the number, but I can’t seem to get how to convert the net worth to a number.
Any help would be appreciated! And apologies for a noob question.
I did look at the autotype documentation, but was getting stuck at two things -
Parsing complex strings like $203B - still can’t wrap my head around how these expressions work, will read up on it
reference to the columns names - i wasn’t specifying them correctly and was getting NaN and undefined which threw me off.
But it’s a lot clearer now. I used the reference in the autotype documentation to write this more concisely - parsedData2 = d3.csvParse(await FileAttachment("bloomberg_billionaires@1.csv").text(), ({rank, name, net_worth, country, industry}) => ({rank: +rank, name: name, net_worth: parseDollars(net_worth), country:country, industry:industry}))
Again, thanks for the prompt response. Much appreciated!
Also, love working in Observable, and excited to get better at d3.