Giter Site home page Giter Site logo

Comments (3)

chamkank avatar chamkank commented on July 23, 2024

Hi there,

The default delimiters are , ,, and _. This was the default chosen in the initial version of hone and it remains as the default to preserve backwards-compatibility. If you want to specify additional delimiters like |, you can use the delimiters option like this:

Module:

import hone

optional_arguments = {
  "delimiters": [" ", "_", ",", "|"] # include whatever delimiters you like
}
Hone = hone.Hone(**optional_arguments)
schema = Hone.get_schema('path/to/input.csv')  # nested JSON schema for input.csv
result = Hone.convert('path/to/input.csv', schema=schema)  # final structure, nested according to schema

Let me know if you have any other questions!

from hone.

kasrad avatar kasrad commented on July 23, 2024

Hi,
Thanks for super quick replies!

My issue is that if you have a csv like this (using default delimiter values):

name,ageX(years),weightX(kg),birthXday,adopted_since \n Tommy,5,3.6,11,2012
you get a json like this:

{ "adopted_since": "2012", "ageX(years)": "5", "birthXday": "11", "name": "Tommy", "weightX(kg)": "3.6" }

I believe you should get a json like this:

{ "adopted" : {"since": "2012"}, "ageX(years)": "5", "birthXday": "11", "name": "Tommy", "weightX(kg)": "3.6" }

It makes sense to me, but there might be some issues with this approach. What do you think?

from hone.

chamkank avatar chamkank commented on July 23, 2024

Oh I see what you're saying now. The idea behind hone was that it would only add structure to your data if there was more than one column that could be nested under a key. "adopted" : {"since": "2012"} looks nice but there isn't a compelling reason to make adopted_since nested if it will only hold a single key. If there were another column like adopted_by, then the structure would make sense because you could then have "adopted" : {"since": "2012", "by": "Bob"}.

It might also get out of hand if you have multiple delimiters in a column name. For example, something like "date last accessed" would become "date" : {"last": { "accessed": ... } } if you were to split it indiscriminately. This would get cumbersome pretty quickly.

If the CSV column names are chosen well, then I can see why you might prefer to split it the way you described, but I don't think it should be the default behaviour for the reasons described above. However, if you want to add an optional argument that a user can use to make hone behave this way, then that would be totally cool with me!

If you need the feature more urgently, you can also modify the schema that hone generates to fit your needs. For example:

import hone

optional_arguments = {
  "delimiters": [" ", "_", ","]
}
csv_file_path = "path/to/input.csv"
Hone = hone.Hone(**optional_arguments)
schema = Hone.get_schema(csv_file_path )
del schema["adopted_since"]
schema["adopted"] = { "since": "adopted_since" }
result = Hone.convert(csv_file_path, schema=schema)

from hone.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.