I am probably able to solve this myself if I had the time to investigate. I've been trying different things but I can't get it to work! I am doing my master in Marketing, and we are expected to be able to code in Python very basically to parse a dataset (json) into an organised text file that can be used for further analysis.
We have a dataset with a lot of missing values. What I want to be parsed is this: artist, mbid (music brainz artist id), event data, venue name, city.
This is (part of) the script I have written for that:
for event in setlists:
eventdate = event.get(u'@eventDate')
venuename = event.get(u'venue').get(u'@name')
mbid = event.get(u'artist').get(u'@mbid')
artistname = event.get(u'artist').get(u'@name')
city = event.get(u'venue').get(u'city').get(u'@name')
f = open(parse_file, 'a')
f.write(artistname+'\t'+mbid+'\t'+eventdate+'\t'+venuename+'\t'+city+'\n')
f.close()
This script works like a charm, except for that it leaves out entries for which there are missing values, e.g. no city.
I want it to report it to a line of text anyway, and print "missing" for the info that is missing.
I can't get it to work and I don't know where to start either. I tried things like this:
f = open(parse_file, 'a')
try: f.write(artistname) except: continue try: f.write(mbid) except: continue...
f.close()
Every line in the parsed file should like like this:
artistname mbid eventdate venuename location
I did try to put everything on different lines but then the problem was the output was vertically and not horizontally for each event.