Jadi saya memiliki kerangka data pandas dengan deretan string yang diberi token di kolom bernama story. Saya juga memiliki daftar kata dalam daftar yang disebut kata_pilihan. Saya mencoba menghitung kemunculan salah satu kata_yang dipilih di setiap baris di kolom cerita.
Kode yang saya gunakan sebelumnya yang berhasil adalah
CCwordsCount=df4.story.str.count('|'.join(selected_words))
Ini sekarang memberi saya nilai NaN untuk setiap baris.
Di bawah ini adalah beberapa baris pertama kolom story di df4. Kerangka data berisi lebih dari 400 baris Artikel NYTimes.
0 [it, was, a, curious, choice, for, the, good, ...
1 [when, he, was, a, yale, law, school, student,...
2 [video, bitcoin, has, real, world, investors, ...
3 [bitcoin, s, wild, ride, may, not, have, been,...
4 [amid, the, incense, cheap, art, and, herbal, ...
5 [san, francisco, eight, years, ago, ernie, all...
Ini adalah daftar kata_yang dipilih
selected_words = ['accept', 'believe', 'trust', 'accepted', 'accepts', 'trusts', 'believes', \
'acceptance', 'trusted', 'trusting', 'accepting', 'believes', 'believing', 'believed',\
'normal', 'normalize', ' normalized', 'routine', 'belief', 'faith', 'confidence', 'adoption', \
'adopt', 'adopted', 'embrace', 'approve', 'approval', 'approved', 'approves']
["it, was, a, curious, choice, for, the, good, ..."]
? - person DarrylG   schedule 13.05.2020