【发布时间】:2018-04-05 21:31:19
【问题描述】:
我有一个我想在下面计算的“单词”列表
word_list = ['one','three']
我在 pandas 数据框中有一列,下面有文字。
TEXT |
-------------------------------------------|
"Perhaps she'll be the one for me." |
"Is it two or one?" |
"Mayhaps it be three afterall..." |
"Three times and it's a charm." |
"One fish, two fish, red fish, blue fish." |
"There's only one cat in the hat." |
"One does not simply code into pandas." |
"Two nights later..." |
"Quoth the Raven... nevermore." |
所需的输出如下,它保留原始文本列,但仅将 word_list 中的单词提取到新列
TEXT | EXTRACT
-------------------------------------------|---------------
"Perhaps she'll be the one for me." | one
"Is it two or one?" | one
"Mayhaps it be three afterall..." | three
"Three times and it's a charm." | three
"One fish, two fish, red fish, blue fish." | one
"There's only one cat in the hat." | one
"One does not simply code into pandas." | one
"Two nights later..." |
"Quoth the Raven... nevermore." |
有没有办法在 Python 2.7 中做到这一点?
【问题讨论】:
标签: python regex string pandas extract