I am trying to extract full name and country code of a "place" from a json file that has thousands of tweets mined from Twitter API. I have tried to write the code several different times, but the code below makes the most sense to me. I was able to extract other data (hashtags, dates, followers with similar coding).
for i in range(len(data)):
if data[i]["place"] != "null":
get_place_info = data[i]["place"].get("full_name")
print(get_place_info)
else:
print("No place defined")
This is the error I get:
AttributeError Traceback (most recent call last) in 3 4 if data[i]["place"] != "null": ----> 5 get_place_info = data[i]["place"].get("full_name") 6 print(get_place_info) 7
AttributeError: 'NoneType' object has no attribute 'get'
adding an answer from my previous comment...
have you tried changing your if statement to
if data[i]['place'] is not None: