in the data, column df[‘comments’] consists of 88107 rows with arrays with dictionaries
`
[{'text': "It will be curious to see where this heads in the long run. CBS is on a tear but will it fit their image, will they try and establish control, overall agenda. I've enjoyed last.fm for many years supporting through paypal donations each time I expire...it'll be interesting.",
'score': 0},
{'text': "Does this mean that there's now a big-name company who will fight for the repeal of the recent streaming-music royalty hike?",
'score': 1},
{'text': 'Also on BBC News: http://news.bbc.co.uk/1/low/technology/6701863.stm .Nice to see a London-based co. hit the headlines.',
'score': 2},
{'text': "I don't understand what they do that is worth $70M a year. ",
'score': 3},
{'text': 'sold out too cheaply. given their leadership position, they should have ask for at least $500m',
'score': 4}]
`
how to make one big table with columns ‘text’ and ‘score’
`l=pd.DataFrame()
for i in range(len(df['comments'][0])+1):
n1=pd.DataFrame(data=df['comments'][i])
l=pd.concat([l, n1], axis=0)`
I was able to make a table from one array, but I can’t open all 88000
enter image description here
3
Answers
If for each value of
comments
is list of dictionaries, need flatten them withDataFrame
constructor:You can use
pd.json_normalize
:Or use
DataFrame
constructor:If you want to remove
comments
column, just replacedf['comments']
bydf.pop('comments')
like:Use list comperhension:
Output: