试图看看哪些细胞中有“+”号,哪些细胞有“-”,哪些细胞同时有“+”号。
df = pd.DataFrame({"result":['XY: (-Y, 25%)', 'XX: (-5q, 20%);(+18, 20%)', 'XX: (-6q25.3-q27, 11.8Mb, 30%)', 'XX: (-1, 25%);(-10q, 20%)', 'XX: (+5, 20%)']})
df我试过用str.contain
gain=df.loc[df['result'].str.contains("+7")]
gain但是当试图传递其中一个字符(+或-) 错误时,得到了一个错误:在位置0没有重复。当只传递一个数字
gain=df.loc[df['result'].str.contains("7")]它工作得很好-没有错误
寻求一些建议。谢谢
发布于 2021-12-06 18:49:44
试图看看哪些细胞中有“+”号,哪些细胞有“-”,哪些细胞同时有“+”号。
你可以试试:
pos=[]
neg=[]
for index in df.index:
if '+' in df.loc[index,'result']:
pos.extend([index])
if '-' in df.loc[index,'result']:
neg.extend([index])看看是否有其他人在里面,比如:
both = []
for item in pos:
if item in neg:
both.extend([item])
print(both)发布于 2021-12-06 18:54:13
放反斜杠(逃逸):
gain=df.loc[df['result'].str.contains("\+7")]https://stackoverflow.com/questions/70250291
复制相似问题