Я выполнил поиск, но у меня возникла проблема с попыткой использовать регулярные выражения для извлечения многострочного текста в столбце pandas фрейма данных и pu sh этих результатов в новый столбец.
Я пытаюсь извлечь все, что находится между двумя повторами «QAT», что включает однострочные и m многострочных предложений / текста.
Пример ниже:
Cust_ID Cust_Review
------------------------------------------------------
101 "QAT - i dislike this toaster, it
Never works right.\n This is the
last time! - QAT"
-----------------------------------------------------
201 "QAT - I love this toaster! - QAT"
-----------------------------------------------------
301 "QAT - I bought this toaster for my
mother, which she loves.\n I will
also be buying another for\n my
sister, she could use it as well. - QAT"
Я пытаюсь извлечь весь промежуточный текст в новый столбец внутри фрейма данных:
Cust_ID Cust_Review Newcolumn_Text
--------------------------------------------------------------------------------------------
101 "QAT - i dislike this toaster, it i dislike this toaster, it
Never works right.\n This is the Never works right.\n This is the
last time! - QAT" last time!
--------------------------------------------------------------------------------------------
201 "QAT - I love this toaster! - QAT" I love this toaster!
---------------------------------------------------------------------------------------------
301 "QAT - I bought this toaster for my I bought this toaster for my
mother, which she loves.\n I will mother, which she loves.\n I will
also be buying another for\n my also be buying another for\n my
sister, she could use it as well. - QAT" sister, she could use it as well.
Я попытался сделать это с помощью регулярного выражения, но могу сказать, что ' m, и любая помощь будет принята с благодарностью.
Моя неудачная попытка:
df['Newcolumn_Text'] = re.search(r'QAT.*QAT', df.Cust_Review, re.DOTALL)
Спасибо!