Comments (3)
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.
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.
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)
- Support for type casting
- Support for custom delimiters
- Differentiate between private helpers & public methods
- cannot import name 'Hone' from 'hone' HOT 8
- Properly escape quotes in cell values
- Document all command-line arguments
- Allow schema to be overridden
- Missing schema in example HOT 7
- Example A not reproducible HOT 4
- Handle BOM at start of CSV files
- Multistring delimiters HOT 3
- Anyway to structure json output values based on column order? HOT 1
- When we pass schema as a json, getting the error
- Custom schema issues / nested arrays
- not recognizing the arrays nested in json
- Support Appending into Embedded structure HOT 4
- Use built-in csv module
- Improve tests
- Require Python 3.0+
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hone.