![]() With open('output.csv', 'w', newline='') as f_output:Ĭsv_output = csv.DictWriter(f_output, fieldnames=sorted(fieldnames))Ĭsv_output.writerows(get_leaves(entry) for entry in json_data) # First parse all entries to get the complete fieldname listįieldnames.update(get_leaves(entry).keys()) Here is the code that should work apart from not being able to have a CSV friendly dict. Notice how the first team did not have the “Venue.ID” which makes things even more difficult. Id, name, link, venue_id, venue_name, venue_link…ġ, New Jersey Devils, /api/v1/teams/1, Prudential Center, /api/v1/venues/nullĢ, New York Islanders, /api/v1/teams/2, 5026, Barclays Center, /api/v1/venues/5026 The desired result would be to like this (this is a shortened version): “copyright” (Cell A2) and “teams” (A3) so it doesnt flatten the dict as I want it to. ![]() However, the CSV that I get only has two cells. I have Googled this quite a bit and the code for flattening the json/dict is from this post. However, I got stuck trying to get the first JSON response to a CSV for further analysis. ![]() Since the NHL season is about to start I am planning on downloading some stats and team info through the NHL API. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |