The new NodeBox forum is live! Everything from support.nodebox.net moved here: sign in with the same email to pick up your old posts. Something not working? Write to forum-support@nodebox.net.

NodeBox 3From the old forum

Extract Column Headers from a CSV file?

6 replies Last reply

  1. I am visualizing CSV files. I can slice and dice the data but would also like to display and manipulate the column headers.

    For some projects I need to do generic lookups without having to hand-code new key values every time I change a file. For example I'd like to simply display the contents of any CSV file - including the headers - as a full-fledged NodeBox visualization (with fonts, colors, grid spacing etc. under my full control) by simply changing the file in the Import Csv node.

    All I need is some way to return the column header keys as individual strings. Even just a way of counting the number of columns in a CSV file would be helpful.

    How do I do this in Nobebox 3?

    Thanks in advance for any suggestions or comments!

    John

    Copy link
  2. In NB3 there is no direct way of getting this. I agree it should be possible. The only way at the moment is cheating by adding a row in your csv file: repeating the headers. Later on you have to omit these rows. I agree this is not a real solution. We'll look into this and see if this can not be handled in the next release.

    regards,

    Lucas

    Copy link
  3. Thanks for the response, Lucas.

    If you are compiling a wish list I have another related feature request.

    It would be very handy to create a two dimensional zip map that would let me create and pass internal CSV data structures from node to node. As far as I can tell, the current zip map can only create a vector of label-value pairs, not a matrix with multiple index rows.

    The output of this improved zip map node would be a data structure just like the output of import CSV. Other nodes could then filter this output and do look ups on it. This would be a very powerful and useful capability.

    Doesn't hurt to ask.

    Thanks again,

    John

    Copy link
  4. Hello John,

    don't forget you can add your own code libraries. Enclosed is a file with a custom node that gets the headers as you want. Then you can count them too if you want...
    Have fun,

    Lucas
    PS: the csvheaders.py needs to be at the same root.

    Copy link
  5. Nice! Thanks, Lucas.

    I was aware of the ability to add my own code libraries, but have been trying to resist it while I'm learning how to think in NodeBox. I find that staying within the standard nodes forces me to explore them more deeply. At first it often looks like something can't be done, but when you look a little deeper there is usually a way.

    But it's impressive how simple it was to add that custom node. Only six short lines of code. I'll keep this in mind next time I get stuck.

    Thanks again!

    John

    Copy link
  6. In the next release there will be a getCSVHeaders node.

    Copy link
  7. NodeBox team

    Hi,

    The new release, 3.0.43, contains the functionality you need. However, the node is called "keys", since it can retrieve the keys of any kind of map-related data, including CSV nodes.

    Another useful feature is that you can append it after a graphic object, in which case it will list the properties of that object that you can retrieve using the lookup node.

    https://www.nodebox.net/download/

    Best,

    F

    Copy link

Know something that helps?

Sign in with your email address to reply. No password needed.

Sign in to reply