-
Notifications
You must be signed in to change notification settings - Fork 313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
provide function to accept data in a flat relational csv format #149
Comments
You can do this using d3.rollups: rollups = d3.rollups(data, v => d3.sum(v, d => d.population), d => d.continent, d => d.country) root = d3.hierarchy([null, rollups], ([, value]) => value)
.sum(([, value]) => value)
.sort((a, b) => b.value - a.value) Live example here: https://observablehq.com/@mbostock/2019-h-1b-employers Related #140. |
Here’s a quick example with your data: |
Thanks for the quick answer and the great examples. But just to clarify - I haven't been clear in the description of the issue: My suggestion was to offer a function that can load this kind of data (wide vs narrow format) if you have the hierarchy (all -> continent -> country) represented in this format:
It is not straight forward to load in into the d3.hierarchy. So if one has this kind of representation one option is to convert it to the long form to obtain: (e.g. ignoring possible property c)
Then you can apply d3.statify() and are ready to go. |
I have been struggling with this as well since the change from |
With the stratify function, the data can be provided as csv in the parent, child format, one per row. Often the data resides in a flat "relational" format, e.g.:
all,continent,country,population
World,Asia,,4436
World,Asia,China,1420
World,Asia,India,1369
World,Africa,,1216
World,Europe,,739
World,North America,,579
World,North America,USA,329
World,South America,,423
World,Oceania,,38
Since its not trivial to convert this data into the supported csv format, it would be great to provide a function, which can convert data in this representation into a hierarchy.
The text was updated successfully, but these errors were encountered: