Last active
October 13, 2017 16:07
-
-
Save AndiH/4d4ef85e2dec395a0ae5343c648565eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"page": 1, | |
"pages": 2270, | |
"limit": 10, | |
"total": 22693, | |
"items": [ | |
{ | |
"address": { | |
"city": "cityname first dataset", | |
"company_name": "companyname first dataset" | |
}, | |
"amount": 998, | |
"items": [ | |
{ | |
"description": "first part of first dataset", | |
"number": "part number of first part of first dataset" | |
} | |
], | |
"number": "number of first dataset", | |
"service_date": { | |
"type": "DEFAULT", | |
"date": "2015-11-18" | |
}, | |
"vat_option": null | |
}, | |
{ | |
"address": { | |
"city": "cityname second dataset", | |
"company_name": "companyname second dataset" | |
}, | |
"amount": 998, | |
"items": [ | |
{ | |
"description": "first part of second dataset", | |
"number": "part number of first part of second dataset" | |
}, | |
{ | |
"description": "second part of second dataset", | |
"number": "part number of second part of second dataset" | |
} | |
], | |
"number": "number of second dataset", | |
"service_date": { | |
"type": "DEFAULT", | |
"date": "2015-11-18" | |
}, | |
"vat_option": null | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
item_address_city | item_address_company_name | items_amount | ||
---|---|---|---|---|
0 | cityname first dataset | companyname first dataset | 998 | |
1 | cityname second dataset | companyname second dataset | 998 |
Whoooho... think I got it: http://pandas.pydata.org/pandas-docs/stable/io.html#normalization
Now adapting it to my data set... keep you posted 💃
Okay, so far so good - in general, it is working, currently I have a slight problem with a "distinguishing prefix" - i think because I am in conflict with 'numbers' - seems to be used in pandas itself?
json_normalize is a great way to "massage" the json data - great tip using pandas!
Now also with working code example... :D
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This here is a good start when using pandas, showing the flattening of arrays: https://medium.com/towards-data-science/flattening-json-objects-in-python-f5343c794b10
The result shown there after normalization is, that the hobbies are put each to an own column.
OK so far - got that.
I'd like to have only one column "hobbies" and then create new lines:
https://www.dropbox.com/s/nm24xqgvdrslkl0/john.jpg?dl=0
The this is, that the information like "John" or "Los Angeles" need to be copied to the next line then.