I am using the Twython library for the first time. It gives me an object 'data' which is of type dictionary. Among the fields of this dictionary is ['user'], which is a sub-dictionary.
I create a list of this dictionary:
tweets=[]
#Given an object data
...some kind of loop....
tweets.append(data)
Once I have that, I've been converting it to a Data Frame:
output = pd.DataFrame(tweets)
which works fine for the first level of dictionaries, but for the 2nd level of dictionaries it converts them all to strings.
Ideally what I would like to be able to do is something like:
output['user']['screen_name'][1]
instead of
user_info = ast.literal_eval(output['user'][1]))
print user_info['screen_name']
and natively access the data. Currently, I have to use something like ast to convert it to another dictionary first on a row-by-row basis. Is there a more efficient way of doing this?