I am working on learning Python and am trying to take a list (comma separated) stored in a file and convert it to a data store that can be sorted with Python with each four strings filling a row. For example if I have the following in the file:
'apples are great'
,'neg': 0.485, 'neu': 0.392, 'pos': 0.123, 'compound': -0.812,
'crayons are waxy'
,'neg': 0.302, 'neu': 0.698, 'pos': 0.0, 'compound': -0.3818,
'a happy girl'
,'neg': 0.0, 'neu': 1.0, 'pos': 0.0, 'compound': 0.0,
'a phone is alive'
,'neg': 0.0, 'neu': 0.737, 'pos': 0.263, 'compound': 0.3612,..........
I would like a dataframe that has the following:
Subject Neg Neu Pos Compound
apples are great 0.485 0.392 0.123 -0.812
crayons are waxy 0.302 0.698 0.0 -0.3818
a happy girl 0.0 1.0 0.0 0.0
a phone is alive 0.0 0.737 0.263 0.3612
My goal is to sort by the compound column and also to look for frequency of words in the first column. I feel like this should be relatively easy, but have tried reading into a dataframe, but it becomes one row with each value in a column, and then also tried to make it a textblob with sentences and again get incorrect results.
Thank you in advance for the help.
Sample of what I have tried
test = open('Heros_toSort.txt')
test2=test.readlines()
df = pd.DataFrame(test2, columns = ['name'])
df.assign(name=df.name.str.split(','))