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 []を使用してみましたが、入力に文字列が含まれているため、ユーザー入力を行う方法がわかりません。
以下のコードを使用すると、データフレームからデータを抽出できます。
sample = input('Enter Sample: ')
location = input('Enter Location: ')
df.loc[(df['Sample'] == sample) & (df['Location'].str.contains(location))]
これは上記のコードの出力です:
Enter Sample: S2
Enter Location: B
Sample Location Repeat Number Identifier
15 S2 B4 1 asd16
16 S2 B5 2 asd17
17 S2 B6 3 asd18
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加