如何在DataFrame Python中迭代行并将每行转换为字符串?
我需要迭代Dataframe中的每一行,并使用正则表达式检查是否有任何行包含“CHG00”模式 正则表达式方法如何在DataFrame Python中迭代行并将每行转换为字符串?,python,Python,我需要迭代Dataframe中的每一行,并使用正则表达式检查是否有任何行包含“CHG00”模式 正则表达式方法 import re def is_valid(x): regexp = re.compile(r'CHG00') return regexp.search(x) is not None df['new_col'] = df['col1'].apply(is_valid) df['new_col'] = df['col1'].str.contains('CHG00')
import re
def is_valid(x):
regexp = re.compile(r'CHG00')
return regexp.search(x) is not None
df['new_col'] = df['col1'].apply(is_valid)
df['new_col'] = df['col1'].str.contains('CHG00')
熊猫方法
import re
def is_valid(x):
regexp = re.compile(r'CHG00')
return regexp.search(x) is not None
df['new_col'] = df['col1'].apply(is_valid)
df['new_col'] = df['col1'].str.contains('CHG00')
输出将是一系列布尔值,
True
作为包含模式的字符串欢迎使用stackoverflow。请详细说明这不是询问stackoverflow问题的正确方式。