我有一个如下所示的熊猫数据框:-
[Route("api/[controller]/[action]")]
public class XmlController : Controller
{
private readonly ITimerService _timerService;
public XmlController(ITimerService timerService)
{
//Injected in
_timerService = timerService;
}
[HttpGet]
public IActionResult ProccessXML(object someXMLObject)
{
_timerService.StopTimer();
SomeMethodWithXml(someXMLObject)
//Reset Timer
_timerService.StartTimer();
return Ok();
}
}
我也有一个类似下面的列表:-
Tweets
0 RT @cizzorz: THE CHILLER TRAP *TEMPLE RUN* OBS...
1 Disco Domination receives a change in order to...
2 It's time for the Week 3 #FallSkirmish Trials!...
3 Dance your way to victory in the new Disco Dom...
4 Patch v6.02 is available now with a return fro...
5 Downtime for patch v6.02 has begun. Find out a...
6 ⛏️... soon
7 Launch into patch v6.02 Wednesday, October 10!...
8 Righteous Fury.\n\nThe Wukong and Dark Vanguar...
9 RT @wbgames: WB Games is happy to bring @Fortn...
现在,如果要从my_list中找到匹配的单词,我想过滤行,并获得整行并将其作为电子邮件发送或发送给空闲人员。
就像我应该在第no行那样得到输出是因为它里面有Dance字。
my_list = ['Launch', 'Dance', 'Issue']
我尝试下面的代码进行过滤,但是每次给我一个空值
3 Dance your way to victory in the new Disco Dom..
如果我有列表中的匹配词,我只想发送与正文相同的电子邮件。
答案 0 :(得分:0)
使用regex=True
例如:
data[data['Tweets'].str.contains("|".join(my_list), regex=True)]
答案 1 :(得分:0)
这将完成它:
import pandas as pd
import numpy as np
from io import StringIO
s = '''
"RT @cizzorz: THE CHILLER TRAP *TEMPLE RUN* OBS..."
"Disco Domination receives a change in order to..."
"It's time for the Week 3 #FallSkirmish Trials!..."
"Dance your way to victory in the new Disco Dom..."
"Patch v6.02 is available now with a return fro..."
"Downtime for patch v6.02 has begun. Find out a..."
"⛏️... soon"
"Launch into patch v6.02 Wednesday, October 10!..."
"Righteous Fury.\n\nThe Wukong and Dark Vanguar..."
"RT @wbgames: WB Games is happy to bring @Fortn... plane 5 [20 , 12, 30]"
'''
ss = StringIO(s)
df = pd.read_csv(ss, sep=r'\s+', names=['Data'])
my_list = ['Launch', 'Dance', 'Issue']
cond = df.Data.str.contains(my_list[0])
for x in my_list[1:]:
cond = cond | df.Data.str.contains(x)
df[cond]