Guest User

Untitled

a guest
Feb 7th, 2019
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. order_response = {
  2. "orders": [
  3. {
  4. "id": '1',
  5. "email": "b@mail.com",
  6. "location_id": 9,
  7. "line_items": [
  8. {
  9. "id": 5,
  10. "product_id": 6,
  11. }, {
  12. "id": 7,
  13. "product_id": 8,
  14. }
  15. ]
  16. }, {
  17. "id": '2',
  18. "email": "b@mail.com",
  19. "location_id": 10,
  20. "line_items": {
  21. "id": 3,
  22. "product_id": 4,
  23. }
  24. },
  25. ]
  26.  
  27. }
  28.  
  29. id email location_id line_items_id line_items_product_id
  30. 1 b@mail.com 9 5 6
  31. 1 b@mail.com 9 7 8
  32. 1 b@mail.com 10 3 4
  33.  
  34. pd.io.json.json_normalize(report_json, ['line_items'], ['id', 'email'], record_prefix='line_items_')
  35.  
  36. report_json = {
  37. "orders": [
  38. {
  39. "id": '1',
  40. "email": "b@mail.com",
  41. "location_id": 9,
  42. "line_items": [
  43. {
  44. "id": 5,
  45. "product_id": 6,
  46. }, {
  47. "id": 7,
  48. "product_id": 8,
  49. }
  50. ]
  51. }, {
  52. "id": '2',
  53. "email": "b@mail.com",
  54. "location_id": 10,
  55. "line_items": [{
  56. "id": 3,
  57. "product_id": 4,
  58. }]
  59. }
  60. ]
  61.  
  62. }
  63. #print (report_json)
  64.  
  65. df = json_normalize(report_json['orders'],
  66. ['line_items'],
  67. ['id', 'email'],
  68. record_prefix='line_items_')
  69. print (df)
  70. line_items_id line_items_product_id id email
  71. 0 5 6 1 b@mail.com
  72. 1 7 8 1 b@mail.com
  73. 2 3 4 2 b@mail.com
Add Comment
Please, Sign In to add comment