I have data as:
import pandas as pd
df2 = pd.DataFrame([[ "I am new at programming."],
[ "Leaves are falling from tree."]], columns = ['Text'])
input file print:
Text
0 I am new at programming.
1 Leaves are falling from tree.
and I have a code that performs NLP task:
NewListA = []
for inputs in df2['Text']:
t = nlp(inputs)
res_A = {}
for sent in t.sentences:
for word in sent.words:
# append to dict
txt= f'{word.text}'
upos= f'{word.upos}'
res_A[txt]= upos
NewList = list(res_A.items())
NewListA.append(NewList)
It output as:
[[('I', 'PRON'), ('am', 'AUX'), ('new', 'ADJ'), ('at', 'ADP'), ('programming', 'NOUN'), ('.', 'PUNCT')], [('Leaves', 'NOUN'), ('are', 'AUX'), ('falling', 'VERB'), ('from', 'ADP'), ('tree', 'NOUN'), ('.', 'PUNCT')]]
This results in an additional outmost list bracket. I want to remove outmost bracket and get:
[('I', 'PRON'), ('am', 'AUX'), ('new', 'ADJ'), ('at', 'ADP'), ('programming', 'NOUN'), ('.', 'PUNCT')], [('Leaves', 'NOUN'), ('are', 'AUX'), ('falling', 'VERB'), ('from', 'ADP'), ('tree', 'NOUN'), ('.', 'PUNCT')]
where I can convert it to dataframe and end up with this:
POS
0 [('I', 'PRON'), ('am', 'AUX'), ('new', 'ADJ'), ('at', 'ADP'), ('programming', 'NOUN'), ('.', 'PUNCT')]
1 [('Leaves', 'NOUN'), ('are', 'AUX'), ('falling', 'VERB'), ('from', 'ADP'), ('tree', 'NOUN'), ('.', 'PUNCT')]
I looked into this solution or this however, these removing all brackets inside the list, which not I what I am looking for.
Note: my desire results example is:
[['A','B'],['B','C']]
--> ['A','B'],['B','C']