Например, у меня есть этот фрейм данных.
Код: Выделить всё
import pandas as pd
import re
df = pd.DataFrame(
{
'Col1': ['Some data 1', 'Some data 2', 'Some data 3'],
'Col2': ['More data 1', 'More data 2', 'More data 3'],
'Text': ['ID:12345;Description: This is a long piece of text containting some information I want to search for;Status=off;',
'Description: This is a another long piece of text containting some different information I want to search for;ID:abcde;Status=on;',
'Status=unknown;ID:abcde;Description: And this is a third piece of long piece of text which I want to search for;']
}
)
Код: Выделить всё
df['Description'] = df['Text'].apply(lambda x: re.search('Description: (.*?);',x))
Код: Выделить всё
Col1 Col2 Text Description
0 Some data 1 More data 1 ID:12345;Description: This is a long piece of text containting some information I want to search for;Status=off;
2 Some data 3 More data 3 Status=unknown;ID:abcde;Description: And this is a third piece of long piece of text which I want to search for;
Подробнее здесь: [url]https://stackoverflow.com/questions/76255745/re-search-is-not-returning-complete-match[/url]
Мобильная версия