Форум сайта python.su
Здравствуйте.
Подскажите, есть pandas dataframe с текстом, нужно найти все слова, отфильтровав все остальное, при этом оставив слова, которые, скажем, от 3-х букв и выше. Я могу это сделать с помощью re.findall, но re.findall возвращает list (для каждой строки). То есть применив
>>> processed_text = sample_text.apply(lambda x: re.findall('[a-zA-Z]{5,}', x))
6 [Plasticity, Mediated, Competitive, Learning] 7 [Morphology, Classification, using, Analogue]
6 Plasticity Mediated Competitive Learning 7 Morphology Classification using Analogue
Отредактировано Kurtz (Янв. 21, 2017 10:11:21)
Офлайн
Сделал в два этапа, как сделать в один пока не понял.
>>> text = 'Hello this is the^& test &%text with some*&* digits 12449/565)^%' >>> preprocessed_text = re.sub('[^a-zA-Z]+', ' ', text) >>> print(preprocessed_text) 'Hello this is the test text with some digits'
>>> result = re.sub(r'\W*\b\w{1,4}\b', '', preprocessed_text.lower()) >>> print(result) 'hello digits'
Отредактировано Kurtz (Янв. 21, 2017 10:12:56)
Офлайн