提取包含任何关键字的句子并将它们存储在另一个 df 列中

Pull sentences including any keywords and store them in another df column

(python, pandas, 等等) 无法找到以下问题的可靠答案:

我有一个主要包含文章的数据框(df['Content'] 是名称。我想在每次包含时提取整个句子(并将 it/them 存储在新列中)任意关键字。

到目前为止,我只能获得每次都被标记的唯一关键字集。如何从内容栏中获取句子?

data = [['2021','If you try on a pair of jeans in Aerie’s dressing room, you’ll be confronted by a slew of post-its with handwritten messages in marker: “Be confident,” “You do you girl,” “We were born to be real. Not perfect.” You can even write your own “body-positive” message for other women to see. “The fitting room is not supposed to be a room of shame,” President and Executive Creative Director of American Eagle and Aerie Jennifer Foyle said. “It’s supposed to be a room to celebrate who you are. That’s a big part of our store experience and brand experience.” Since 2014 the American Eagle subsidiary has rebuilt its brand around self-acceptance through its Aerie REAL campaign. It began with a commitment to stop airbrushing photos of models and has evolved into an elaborate digital marketing effort including the recruitment of a diverse set of ambassadors and models like Olympic gymnast Aly Raisman and body-positive influencer and model Remi Bader. Aerie has gained recognition for slowly outpacing lingerie giant Victoria’s Secret, whose supermodel Angels began to seem like cultural relics. Victoria’s Secret — which closed hundreds of stores as its parent company, L Brands, was rocked by charges of sexual harassment and the revelation of close ties between its founder, Leslie H. Wexner, and Jeffrey Epstein — has attempted to rebrand by doing away with the Angels and enlisting the help of new brand representatives like Megan Rapinoe. American Eagle Outfitters’ stock price is up 29.99% year to date at .83 per share. Victoria’s Secret, which split from L Brands and began trading in August under its own ticker, VSCO, on the New York stock exchange. VSCO is up 4.83% since August at .13 per share, though down more than 25% from L Brands’ 2015 peak of .92 per share. Ten years ago, you might’ve bought a bra because you saw it on an ultra-thin model in a store window or on a woman in a luxurious-looking television ad. Deficit marketing — encouraging people to buy products based on qualities, ideals, or a lifestyle that they don’t have — allows brands to capitalize on longing and insecurity. But increased awareness around issues like women’s body image and the impact of social media on mental health is changing business decisions. Aerie — which has sparked 28 consecutive quarters of double-digit growth for the company —  has shown consumers are also inclined to buy products based on values they want to align with as opposed to the people they want to become. “There’s been a shift from that towards this other type of marketing that is trying to say: Our product incarnates these values. You as a person have these also good values and therefore by buying our product you are enacting those values,” Rachel Rodgers, associate professor in the Department of Applied Psychology at Northeastern University said. Rodgers researched body-positive marketing campaigns, focusing on Aerie’s, in 2019. Participants in the study, undergraduates aged 18 to 23, said that they viewed the brand in a more positive light because of its promise not to airbrush photos. “We paved the way, Aerie did,” Foyle said. “I think we took a very bold move in fashion, we were the first to do so and we set out to not airbrush our models and have that become part of the Aerie brand which now you would know as Aerie REAL.” Other brands have rolled out similar marketing campaigns focused on empowerment and body positivity, dating back to the early 2000s. Unilever, the owner of Dove, started the Dove Campaign for Real Beauty in 2004, to promote confidence among young women. The National Eating Disorders Association, which Aerie has a partnership with, has highlighted other body-positive campaigns including Dressbarn’s More Than a Name, Always’ #LikeAGirl, and Glossier’s Body Hero campaign. Aerie’s focus on more realistic, inclusive models has been accompanied by substantial business successes for the brand, according to associate partner at Clarkston Consulting Sean Burke. “Inclusive marketing is a big trend across the board and they’re one of the ones who seems to have embraced it the best,” he said. Burke also noted that there has been intense “disruption” in the retail space over the past few years, which makes Aerie’s sustained success all the more impressive. The company has also managed to leverage the rise of TikTok to its advantage by using influencer marketing to boost sales. “Why spend tons of money to put a generic commercial up and not know if you’re going to have a captive audience at that point in time when you can pay an influencer who has potentially millions of followers, and many of them very loyal, and some of which have cultured a community to where people want to follow exactly what this person’s doing or feel like you’re part of a group in doing so?” Burke said. It’s not just big names like Raisman and Bader who are generating revenue for Aerie, though. According to Burke, the brand has also effectively used micro-influencers to push their content to smaller audiences. “There are big influencers out there that can generate a lot of the more viral nature of marketer influencing, but these micro-influencers have these really tight communities that can be positive,” he said. While Aerie has successfully rebranded around “body positivity,” there’s a conflict of interest that occurs when a brand is using values-based marketing to encourage a customer to buy something. Still, as Rodgers’ research indicates, Aerie’s marketing efforts appear to serve young women in making them feel less insecure about themselves while buying things. “There is an inherent tension between selling something — I mean it’s more obvious if the product is something like cellulite cream — and saying at the same time ‘but you should love your body!’ Rodgers said. “At the same time, if it leads brands to change their imagery, is that not yet still a good thing?”'],['2018','Aerie has extended its inclusive advertising campaign by featuring women with medical conditions and disabilities in “Aerie Bras Make You Feel Real Good.” Among the models for the Aerie undergarments are women who use wheelchairs, some with an ostomy bag and insulin pump prominently displayed, and Paralympic gymnast Chelsea Werner, who has Down Syndrome, AdWeek reported. Others include a woman who uses forearm crutches, a woman with fibromyalgia and one with vitiligo, a chronic skin disease. Women are shown with body hair and with no hair as a result of cancer treatment. See examples in the gallery below. Nearly 2,000 women responded to a social media casting call for the #AerieREAL campaign, and 57 were selected to “represent the inclusive beauty that makes up the DNA of the brand, which is committed to empowering all customers to embrace and love their real selves,” per Ad Age. "Our newest bra models are part of our brands ongoing commitment to show real, authentic and un-retouched women, who are at the core of everything that we do," Jennifer Foyle, Aerie global brand president, told Fashionista. Many women responded to the campaign with delight on social media. The company launched the #AerieReal body-positive campaign featuring un-retouched advertising photos of women of all skin tones and sizes and in 2014. Gold medal gymnast Aly Raisman, singer-songwriter Rachel Platten and actress-activist Yara Shahidi joined the campaign as “spokesmodels” in January. Comparable sales for Aerie, a sub-brand of American Eagle Outfitters (NYSE: AEO),increased 38 percent in the first quarter of 2018 ended May 5, while comparable sales for American Eagle rose 4 percent overall. “After starting a body positivity movement, Aerie is posting record growth rates and striking a real emotional connection with its expanding customer base,” said Jay Schottenstein, AEO’s chief executive officer, in a statement. “We are highly focused on our strategic plan, centered on expanding American Eagle, accelerating Aerie’s growth, elevating the customer experience and delivering strong financial returns."']]
df = pd.DataFrame(data, columns=['Year','Content'])

keywords = ['diverse','diversity','body positive', 'body positivity','body shaming','body confidence']

df['keywords'] = df['Content'].str.findall('|'.join(keywords)).apply(set)

我在想我应该按照

做点什么
for each_cell in dataframe:
     for each_sentence in cell:
          df['key_sentences'] = [s for s in sentences if s in keywords]

我只是不知道该怎么做。 TIA

您会在这里发现一些挑战,例如 body-positivity 出现在您的一个句子中但不是关键字。您可能会遗漏很多变化。但是,您可以通过将所有单个句子拆分成行,然后使用正则表达式查找匹配项来初步尝试。如果需要,您可以将这些备份到匹配列表中。

df = df.assign(Sentences=df['Content'].str.split('\.\s+')).explode('Sentences')
df = df.loc[df['Sentences'].str.contains('|'.join(keywords))].groupby(['Year','Content'])['Sentences'].apply(list).reset_index()