【发布时间】:2021-09-27 15:53:30
【问题描述】:
我有一个这样的数据框:
text
Is it possible to apply [NUM] times
Is it possible to apply [NUM] time
Called [NUM] hour ago
waited [NUM] hours
waiting [NUM] minute
waiting [NUM] minutes???
Are you kidding me !
Waiting?
我希望能够检测到具有"[NUM] time" or "[NUM] times" or "[NUM] minute" or "[NUM] minutes" or "[NUM] hour" or "[NUM] hours" 的模式。另外,如果它有"!" (or more than one !) 或"??" (at least two ?)。
所以结果应该是这样的:
text. available
Is it possible to apply [NUM] times. True
Is it possible to apply [NUM] time. True
Called [NUM] hour ago True
waited [NUM] hours True
waiting [NUM] minute True
waiting [NUM] minutes??? True
Are you kidding me ! True
Waiting? False
I didn't like it False
所以我想要这样的东西,但不知道如何将所有这些条件放在一起:
df["available"] = df['text'].apply(lambda x: re.match(r'[\!* | \?+ | [NUM] time | [NUM] hour | [NUM] minute]')
【问题讨论】: