Skip to content
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

Add column function to dsv.parse #2429

Closed
wants to merge 1 commit into from
Closed

Conversation

pietersv
Copy link

This adds an optional function to transform column names to dsv.parse(...), comparable to the row accessor added in #1107,

The motivation is that input datafiles may have column names...

  • with arbitrary case generated from other packages that are case insensitive like SAS or SPSS, requiring conversion to some defined case in Javascript
  • with duplicate / missing column names, that need to be deduped, cleaned up, or invented, (e.g. see rules for "Variable Names" in Stat/Transfer

Tests are added that cover these two examples:

var rows = d3.csv.parse(csv, null, function(name) { return name.toLocaleLowerCase(); })
var rows = d3.csv.parse(csv, null, function(name, i) { return "var"+i; })

http://stackoverflow.com/questions/26998476/right-way-to-modify-d3-csv-to-lower-case-column-names

@mbostock mbostock added the req label Oct 21, 2015
@mbostock mbostock added this to the Icebox milestone Oct 21, 2015
@mbostock
Copy link
Member

mbostock commented Jan 6, 2016

I feel the existing row accessor function is sufficient for renaming columns. For example, to lower-case column names:

var rows = d3.csv.parse(csv, function(d) {
  return {
    a: d.A,
    b: d.B,
    c: d.C
  };
});

It’s easiest if you know the column names, but you could, I suppose, write the code generically (at the cost of performance and complexity). Or you could replicate the approach taken by dsv.parse and wrap dsv.parseRows.

I agree that having a dedicated function for remapping columns is simpler, but I think the existing API is sufficient and we should endeavor to keep the API small.

@mbostock mbostock closed this Jan 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants