Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中使用正则表达式根据某种模式删除某些行_Python_Regex - Fatal编程技术网

在python中使用正则表达式根据某种模式删除某些行

在python中使用正则表达式根据某种模式删除某些行,python,regex,Python,Regex,我有一个包含一些文本列的数据表。我想删除那些有MN后跟一些数字的行。例如MN 894080/901060/905034、MN 90706等 import pandas as pd data= [ "MN 894080/901060/905034 - a file has some text.", "L2 BLOCK AMER] [VVol MN 941737][DU MN 934010] a file has some text", "MN 907068 || bdheks;", "MN#287

我有一个包含一些文本列的数据表。我想删除那些有MN后跟一些数字的行。例如MN 894080/901060/905034、MN 90706等

import pandas as pd
data= [
"MN 894080/901060/905034 - a file has some text.",
"L2 BLOCK AMER] [VVol MN 941737][DU MN 934010] a file has some text",
"MN 907068 || bdheks;",
"MN#287627/901060/905034 a file has some text ",
"MN# 944179 || a file has some text",
"(MN #927427)a file has some text",
"MN 933281 - a file has some text",
"a file has some text",
" a file has some text Mnuq"]
df<-pd.DataFrame(data)

df.loc[~df[0].str.contains(r'MN.*\d+')]
df
  data
a file has some text
a file has some text Mnuq
import pandas as pd
data= [
"MN 894080/901060/905034 - a file has some text.",
"L2 BLOCK AMER] [VVol MN 941737][DU MN 934010] a file has some text",
"MN 907068 || bdheks;",
"MN#287627/901060/905034 a file has some text ",
"MN# 944179 || a file has some text",
"(MN #927427)a file has some text",
"MN 933281 - a file has some text",
"a file has some text",
" a file has some text Mnuq"]

_re_remove = re.compile('MN.*\d+')
df = pd.DataFrame(row for row in data if not _re_remove.search(row))