Значение поиска столбца в другом столбце фрейма данных - PullRequest
0 голосов
/ 16 июня 2020

В столбце заголовка есть такие ключевые слова, как собака, вы должны выполнить поиск в той же строке в столбце под названием «Текст», затем создать новый столбец с именем предложение и написать фразу, в которой было найдено это слово.

import pandas as pd

PAL = {'TITLE': ['CAT','DOG','MOUSE','BIRD'],
        'TEXT': ["""
I like small dogs. 
I do not like cats. Birds fly through the sky. 
A mouse eat cheese and they are small""","""
I like small dogs. 
I do not like cats. 
Birds fly through the sky. A mouse eat cheese and they are small""","""
I like small dogs. 
I do not like cats. Birds fly through the sky. 
A mouse eat cheese and they are small""","""
I like small dogs. 
I do not like cats. Birds fly through the sky. 
A mouse eat cheese and they are small"""]
        }

df = pd.DataFrame(PAL, columns = ['TITLE', 'TEXT'])

print (df)

enter image description here

import pandas as pd

PAL = {'TITLE': ['CAT','DOG','MOUSE','BIRD'],
        'TEXT': ["""
I like small dogs. 
I do not like cats. Birds fly through the sky. 
A mouse eat cheese and they are small""","""
I like small dogs. 
I do not like cats. 
Birds fly through the sky. A mouse eat cheese and they are small""","""
I like small dogs. 
I do not like cats. Birds fly through the sky. 
A mouse eat cheese and they are small""","""
I like small dogs. 
I do not like cats. Birds fly through the sky. 
A mouse eat cheese and they are small"""],
     'SENTENCE':["I do not like cats","I like small dogs","A mouse eat cheese and they are small","Birds fly through the sky"]   }

df = pd.DataFrame(PAL, columns = ['TITLE', 'TEXT','SENTENCE'])

print (df)

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...