Yelp / dataset-examples

Samples for users of the Yelp Academic Dataset
http://www.yelp.com/academic_dataset
Other
1.23k stars 615 forks source link

'NoneType' object is not subscriptable error when yelp_academic_dataset_business.json conversion #56

Open zoldaten opened 3 years ago

zoldaten commented 3 years ago

I`ve converted all datasets in yelp_dataset except yelp_academic_dataset_business.json. It returns a error:

Traceback (most recent call last):
  File "json_to_csv_converter2.py", line 129, in <module>
    read_and_write_file(json_file, csv_file, column_names)
  File "json_to_csv_converter2.py", line 21, in read_and_write_file
    csv_file.writerow(get_row(line_contents, column_names))
  File "json_to_csv_converter2.py", line 97, in get_row
    column_name,
  File "json_to_csv_converter2.py", line 89, in get_nested_value
    return get_nested_value(sub_dict, sub_key)
  File "json_to_csv_converter2.py", line 84, in **get_nested_value**
    return d[key]
TypeError: 'NoneType' object is not subscriptable

I`ve changed in script from:

if '.' not in key:
        if key not in d:
            return None
        return d[key]

to

if '.' not in key:
        if d==None:
            return None
        elif key not in d:
            return None
        return d[key]

and problem solved. But i do not think that`s the right way...