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

business.json is not converted to business.csv #53

Closed shahid1579 closed 4 years ago

shahid1579 commented 4 years ago

business.json is not converted to business.csv TypeError: argument of type 'NoneType' is not iterable

fuyi1215 commented 4 years ago

def get_nested_value(d, key): """Return a dictionary item given a dictionary d and a flattened key from get_column_names.

Example:

    d = {
        'a': {
            'b': 2,
            'c': 3,
            },
    }
    key = 'a.b'

    will return: 2

"""
print (key)
print(d)

if '.' not in key:
    if key not in d:
        return None
    return d[key]
base_key, sub_key = key.split('.', 1)
if base_key not in d:
    return None
sub_dict = d[base_key]
**if sub_dict is None:
    return None**
return get_nested_value(sub_dict, sub_key)

Because some json data don't have nested value. the value is null,so the recursion can get NoneType. add one line check "sub_dict is None: return None" to break the recursion. After that, It will be working fine.

shahid1579 commented 4 years ago

@ Thanks @fuyi1215 you Solved my Problem.