python中要列出的特殊字符
我有数据帧python中要列出的特殊字符,python,pandas,Python,Pandas,我有数据帧 data2 = {'col0' : ['USD<500','AUD>100','GBP>200'], 'col1' : ['weights(kgs)','weights(lbs)','weights(gms)'], 'col2' : ['USD$500','AUD$400','GBP$450'], 'col3' : ['height[cm]','height[mm]','height[m]'],
data2 = {'col0' : ['USD<500','AUD>100','GBP>200'],
'col1' : ['weights(kgs)','weights(lbs)','weights(gms)'],
'col2' : ['USD$500','AUD$400','GBP$450'],
'col3' : ['height[cm]','height[mm]','height[m]'],
'col4' : ['length*10%','length*100%','length*1000%'],
'col5' : ['exp^2','exp^3','exp^4'],
'col6' : ['length.height','height.weight','length.weight'],
'col7' : ['len?ht','ht?wt','len?wt'],
'col8' : ['length+height','height+weight','length+weight']}
df2 = pd.DataFrame(data=data2)
这些字符抛出错误为:无需重复
和“$”显示在所有字符串中
我可以知道如何提取字符吗
"<",">","-","/","@","!","~","#","&","?","`"," ",",",":",";"
预期结果
avaichars = ["<",">","(",")","$","[","]","%","*","^",".","?","+"]
avichars=[“”、“(“,”)、“$”、“[”、“]”、“%”、“*”、“^”、“?”、“+”]
看起来像str.contains
也将regex作为默认值。str.contains
函数有一个名为regex
的参数,默认为true。尝试将其设置为false。正如注释所述,它似乎是一个正则表达式,因此可以通过在无法获取的字符串开头添加反斜杠来获取它。我检查了。是的,设置df2[col].str.contains(ch,regex=False)有效
"(",")","[","]","*","^",".","?","+","%"
avaichars = ["<",">","(",")","$","[","]","%","*","^",".","?","+"]