data = {'Sample':['S1', 'S1', 'S1' ,'S1' ,'S2' ,'S2' ,'S3' ,'S3', 'S4', 'Negative', 'Positive', 'Negative',
'S1', 'S1', 'S1' ,'S2' ,'S2' ,'S2' ,'S3' ,'S4', 'S4', 'Positive', 'Positive', 'Negative'],
'Location':['A1', 'A2', 'A3' ,'A4' ,'A5' ,'A6' ,'A7' ,'A8', 'A9', 'A10', 'A11', 'A12',
'B1', 'B2', 'B3' ,'B4' ,'B5' ,'B6' ,'B7' ,'B8', 'B9', 'B10', 'B11', 'B12'],
'Repeat Number':['1', '2', '3' ,'4' ,'1' ,'2' ,'1' ,'2', '1', '1', '1', '2',
'1', '2', '3' ,'1' ,'2' ,'3' ,'1' ,'1', '2', '1', '2', '1',],
'Identifier' :['asd01', 'asd02', 'asd03', 'asd04', 'asd05', 'asd06', 'asd07', 'asd08', 'asd09'
,'asd10' ,'asd11' ,'asd12' ,'asd13' ,'asd14' ,'asd15', 'asd16', 'asd17', 'asd18',
'asd19', 'asd20', 'asd21', 'asd22', 'asd23', 'asd24']}
df1 = pd.DataFrame(data)
在上面的框架中,位置组A中有4个S1,它们是重复的,因为它们在同一位置组A中。对于位置B,有3个S1,它们是重复的,因为它们在同一位置组B中。因此,它们被赋予了重复编号(1,2,3,…)
对于上面的示例代码,当我为“Sample”、“Location”提供用户输入时,我希望提取行本身及其重复
例如,如果我为“样本”输入负数,为“位置”输入A,理想结果如下所示:
data = {'Sample':[ 'Negative', 'Negative'],
'Location':[ 'A10', 'A12'],
'Repeat Number':[ '1', '2'],
'Identifier' : ['asd10' ,'asd12']}
另外,我想知道如何仅在行选择之后提取标识符
我试着使用df.loc[],但我不知道如何在上面进行用户输入,因为输入包含字符串
只需将您的条件链接起来并使用
to_dict("list")
:试试这个:
df[(df.Sample=='Negative') & (df.Location.str.startswith('A'))]
使用以下代码,您将能够从dataframe提取数据:
这是上述代码的输出:
相关问题 更多 >
编程相关推荐