Hi I am beginner in python & R. I had a quick question:
#I have a data frame that looks like this:
# Import pandas library
import pandas as pd
# initialize list of lists
data = [['BarackObama', {'cap': {'english': 0.014543680863094452, 'universal': 0.005213309669283597},
'categories': {'content': 0.13252377443365895, 'friend': 0.27037007428252813,
'network': 0.07904647486470226, 'sentiment': 0.13142975907620189,
'temporal': 0.0560116435619808, 'user': 0.2120791504162319},
'display_scores': {'content': 0.7, 'english': 1.1, 'friend': 1.4, 'network': 0.4,
'sentiment': 0.7, 'temporal': 0.3, 'universal': 0.6, 'user': 1.1},
'scores': {'english': 0.22180647190550215, 'universal': 0.11116719108518804},
'user': {'id_str': '813286', 'screen_name': 'BarackObama'}}],
['realDonaldTrump', {'cap': {'english': 0.0014187924969112314, 'universal': 0.0018655051726169808},
'categories': {'content': 0.062020196630026815, 'friend': 0.19869669732913162,
'network': 0.05312993020038088, 'sentiment': 0.05985886859558471,
'temporal': 0.07924665710801207, 'user': 0.037517839108884524},
'display_scores': {'content': 0.3, 'english': 0.2, 'friend': 1.0, 'network': 0.3,
'sentiment': 0.3, 'temporal': 0.4, 'universal': 0.2, 'user': 0.2},
'scores': {'english': 0.03265990956683609, 'universal': 0.032398754737074244},
'user': {'id_str': '25073877', 'screen_name': 'realDonaldTrump'}}]]
# Create the pandas DataFrame
df = pd.DataFrame(data, columns=['Name', 'botScore'])
# print dataframe.
print(df)
# Name botScore
#0 BarackObama {'cap': {'english': 0.014543680863094452, 'uni...
#1 realDonaldTrump {'cap': {'english': 0.0014187924969112314, 'un...
so how can I have something like this where I choose the keys & values from display_score
portion of the json in dataframe and append them to existing data frame?
# data-wrangling part using the display_scores key in json column....
# print(df)
# Name botScore english friend sentiment
#0 BarackObama {'cap':... 1.1 1.4 0.7
#1 realDonaldTrump {'cap':... 0.3 1.0 0.3
I would really appreciate your help in this! I looked at several past posts but I couldn't solve my problem using their approach:
Creating Dataframe with JSON Keys
How to insert specific keys from json file into a data frame in Python