Python 正则表达式数据帧匹配
Python Regex DataFrame match
我有一个 DataFrame,如果我的正则表达式与此 DataFrame 的其中一行的名称匹配,我想执行排序。
“re”库中有帮助我的选项吗?
我尝试使用这段代码但没有成功
预先感谢您的回答
regex = r"D.*cube"
for row in range(len(df)):
for col in range(len(df.columns)):
if df.iloc[row, col] == regex:
#treatment...
.............
我想你可能想要
pattern = r"D.*cube"
for row in range(len(df)):
for col in range(len(df.columns)):
if re.match(pattern, df.iloc[row, col]):
#treatment...
.............
我有一个 DataFrame,如果我的正则表达式与此 DataFrame 的其中一行的名称匹配,我想执行排序。 “re”库中有帮助我的选项吗? 我尝试使用这段代码但没有成功 预先感谢您的回答
regex = r"D.*cube"
for row in range(len(df)):
for col in range(len(df.columns)):
if df.iloc[row, col] == regex:
#treatment...
.............
我想你可能想要
pattern = r"D.*cube"
for row in range(len(df)):
for col in range(len(df.columns)):
if re.match(pattern, df.iloc[row, col]):
#treatment...
.............