次のように、データフレームの2つの列から値を交換するのに苦労しています。
rs649071 rs640249 0.265 0.49
rs647621 rs640249 0.227 0.34
rs644339 rs640249 0.116 0.08
rs641563 rs640249 1.0 33.96
rs640249 rs11073074 0.248 0.77
rs640249 rs11637397 0.194 0.68
アイデアは、列2の各セルがrs640249であるかどうかをテストし、そうでない場合は、列1から対応する文字列に変更することです。その逆も同様です。このようにすると、最終的な結果は次のようになります。
rs649071 rs640249 0.265 0.49
rs647621 rs640249 0.227 0.34
rs644339 rs640249 0.116 0.08
rs641563 rs640249 1.0 33.96
rs11073074 rs640249 0.248 0.77
rs11637397 rs640249 0.194 0.68
タプルを反復処理しようとしましたが、タプルはアイテムの割り当てをサポートしていません。
rscode='rs640249'
for inf in LDfiles:
df = read_csv(inf, sep='\t', skiprows=1, names=['A', 'B', 'C'])
for tup in df.itertuples():
if tup[2] != rscode:
tup[1], tup[2] = tup[2], tup[1]
print(tup)