Let's say I have one column in a dataframe which has list of list:
id pos
0 1 [[['Malaysia','NR'], [':','PU'], ['Natural','JJ'], ['selling price','NN']]]
1 2 [[['Spot Price','NN'], [':','PU'], ['cotton','NN'], ['India', ' NR']]]
or in dictionary format:
[{'id': 1,
'pos': "[[['Malaysia','NR'], [':','PU'], ['Natural','JJ'], ['selling price','NN']]]"},
{'id': 2,
'pos': "[[['Spot Price','NN'], [':','PU'], ['cotton','NN'], ['India', ' NR']]]"}]
How could I filter if second element of list is NR or NN then split (explode) pos column row-wisely as follows:
id words part_of_speech
0 1 Malasia NR
1 1 selling price NN
2 2 Spot price NN
3 2 cotton NN
4 2 India NR
How could I acheive this in Python? Thanks.
Trial code:
l = [[['Malaysia','NR'], [':','PU'], ['Natural','JJ'], ['selling price','NN']]]
for elem in l[0]:
print(elem[1])
Out:
NR
PU
JJ
NN