【发布时间】:2019-12-06 08:54:51
【问题描述】:
我将一些 JSON 数据转换为 Pandas DataFrame。我正在寻找其字符串内容与多词短语列表匹配的所有列。
我正在处理大量 Twitter JSON 数据already downloaded for public use(因此 Twitter API 使用不适用)。此 JSON 被转换为 Pandas DataFrame。可用的列之一是text,它是推文的正文。一个例子是
We’re kicking off the first portion of a citywide traffic calming project to make residential streets more safe & pedestrian-friendly, next week!
Tuesday, July 30 at 10:30 AM
Nautilus Drive and 42 Street
我希望能够拥有一个短语列表phrases = ["We're kicking off", "we're starting", "we're initiating"] 并执行pd[pd['text'].str.contains(phrases)]] 之类的操作,以确保我可以获得text 列包含其中一个短语的pandas DataFrame 行。
这可能要求太多,但理想情况下我也可以匹配phrases = ["(We're| we are) kicking off", "(we're | we are) starting", "(we're| we are) initiating"]之类的东西
【问题讨论】:
-
请也发布示例数据和预期输出
-
@anky_91 我刚刚更新了!