![]() Return left.assign(key=1).merge(right.assign(key=1), on='key', how='outer').drop('key', 1)ĭf = cross_join(df, to_frame(data, prev_key + '.' + key))ĭf = ncat(, prev_key)])ĭf = pandas.DataFrame(, This is an older question, but I struggled the entire night to get a satisfactory result for a similar situation, and I came up with this: import json Please scroll down for the newer, faster solution Note that this is just the short version. The desired output should be something like this: company_number, address_line_1, locality, country_of_residence, kind,ġ2345678, Address 1, Henley-On-Thamed, England, individual-person-with-significant-control I know that this is easy to accomplish with pandas module but I am not familiar with it. "self": "/company/12345678/persons-with-significant-control/individual/bIhuKnFctSnjrDjUG8n3NgOrl" "kind": "individual-person-with-significant-control", I have a large nested JSON file (1.4GB) and I would like to make it flat and then convert it to a CSV file. ![]() I tried several solutions but I couldn't solve my problem. Gender_unknown = meetupĬsv_writer.I know this question has been asked many times. import jsonĭata_to_file = open(output_file, 'w', newline='')Ĭsv_writer = csv.writer(data_to_file, delimiter=" ")Ĭsv_writer.writerow() The JSON was too nestled and complex to parse, so now I just read the fields I need from the data. ![]() If anyone else has the same problem, I solved it, not very elegantly, but I needed the data. Therefore, the description of the value should be listed just once, as a header, and the values listed beneath (new lines and pipes indicating a new field of a csv sheet): RSVPs_per_event | Organizer | ID I get multiple Meetup groups in the reply, all having the same structure as shown above. Any help is really appreciated, and it would be great if it was Python3 compatible.Įdit: What I would like it to look like in the end: However, if I don't write it as a list, I only get the fields of the JSON object, without the data, so it would just be 'Organizers', 'Name' etc, without the actual name.Īs I said, I am a python beginner and haven't found any libraries to help me with it, but I'm sure they exist. So basically, the whole JSON object in a single CSV field, with weird 'u's, in lists and so on. This leads to a really ugly output, looking like this (again, the values in caps are anonymized): Now, as you can see, I write into the CSV as a list. My code, anonymized: import jsonĭata = requests.get(url_path, params=params) Getting the data is not a problem, but I can't seem to parse the JSON object into a proper CSV file. I've never worked with JSON or Python, so I've run into some issues. I need to get some data from the Meetup API, convert the JSON I get into a CSV, all of that in Python 3.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |