,可以通过以下步骤实现:
import re
import pandas as pd
data = {'text': ['This is a (sample) text', 'Another [example] text', 'No brackets here']}
df = pd.DataFrame(data)
def extract_text(row):
pattern = r'\b\w+\b' # 正则表达式模式,匹配单词
text = row['text']
matches = re.findall(pattern, text)
return ' '.join(matches) # 将匹配到的单词用空格连接起来
df['new_column'] = df.apply(extract_text, axis=1)
这样,新列"new_column"将包含不带括号的文本。例如,对于示例数据框,新列的值将分别为:"This is a text", "Another example text", "No brackets here"。
请注意,以上代码示例中没有提及腾讯云相关产品和产品介绍链接地址,因为在这个特定的问题中没有与云计算相关的内容。如果您有其他关于云计算的问题,我将很乐意为您提供相关的答案和推荐腾讯云的产品。
领取专属 10元无门槛券
手把手带您无忧上云