Skip to content
Advertisement

How do I traverse through a dataframe and get polarity score of existing text(transcript) so I have 1 row per id in python?

I am able to traverse through files in a directory with my script but unable to apply the same logic to when all the transcriptions are in a table/dataframe. My earlier script –

JavaScript

How do I apply the above to the below table where

JavaScript

So as you see here, I have a column interaction id which is unique. I my final data set to give me 1 row per id and I require to get the polarity scores of the sentiments attached to that id.

Desired output for 100390719220210104 –

JavaScript

How can I do this for all interaction id? I was able to do it when i had to apply my script to all transcripts csvs in a directory and iterate through them all. However, how can I apply that to a dataframe where all the data is in one place and not different csvs

Advertisement

Answer

So rather than looping through the files, you are looping through the unique InteractionIds. You can get that using: for interaction_id in dfo['InteractionId'].unique()

And then you are joining the values in that column for that ID which you can get by:
' '.join(dfo[dfo['InteractionId'] == interaction_id]['Transcript'])

Putting it together you have:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement