У меня есть датафрейм с именем df
Gender Country Comments
male USA machine learning and fraud detection are a must learn
male Canada monte carlo method is great and so is hmm,pca, svm and neural net
female USA clustering and cloud computing
female Germany logistical regression and data management and fraud detection
female Nigeria nltk and supervised machine learning
male Ghana financial engineering and cross validation and time series
и список алгоритмов
algorithms = ['machine learning','fraud detection', 'monte carlo method', 'time series', 'cross validation', 'supervised machine learning', 'logistical regression', 'nltk','clustering', 'data management','cloud computing','financial engineering']
Технически, для каждой строки столбца комментариев я пытаюсь извлечь слова, которые появляются в списке алгоритмов.
Это то, чего я пытаюсь достичь
Gender Country algorithms
male USA machine learning, fraud detection
male Canada monte carlo method, hmm,pca, svm, neural net
female USA clustering, cloud computing
female Germany logistical regression, data management, fraud detection
female Nigeria nltk, supervised machine learning
male Ghana financial engineering, cross validation, time series
Тем не менее, это то, что я получаю
Gender Country algorithms
male USA
male Canada hmm pca svm
female USA clustering
female Germany
female Nigeria nltk
male Ghana
слова, такие как машинное обучение и обнаружение мошенничества, не отображаются. в основном все 2 грамма слова
Это код, который я использовал
df['algorithms'] = df['Comments'].apply(lambda x: " ".join(x for x in x.split() if x in algorithms))