I define a function as follows...
def getSentiment(x):
vs = vaderSentiment
col = vs(x['messages'].encode('utf-8', 'replace'))
return col
The column of the DataFrame I am applying the function to contains individual strings per row (two examples)...
There are some classic 'Cat' ones about seatbelts
That would be the fighters steroids… I've told you
When I apply the function using...
df['sentiment']=df.apply(getSentiment, axis=1)
The dicts that resulted from the function are converted into string format in the new sentiment column (two rows as examples)...
sentiment
{'compound': 0.4404, 'neg': 0.0, 'neu': 0.919, 'pos': 0.081}
{'compound': 0.4404, 'neg': 0.0, 'neu': 0.256, 'pos': 0.744}
Instead of this, is there a way to apply the function so that the key value pairs from the dict are returned as individual columns (in addition to the other variables), like this in effect:
compound neg neu pos
0.4404 0.0 0.919 0.081
0.4404 0.0 0.256 0.744
Amongst other things I've tried using DataFrame.from_dict and searching some other answers on here but nothing seems applicable.
messagesin it. That's what function is applied to.