濃度データと座標を含む2つのデータフレームがあります。
濃度データ(濃度):
Sample analParam Conc Units
0 CW7-1 1,1,1-Trichloroethane 0 UG/L
1 CW7-1 1,1,2,2-Tetrachloroethane 0 UG/L
2 CW7-1 1,1,2-Trichloroethane 0 UG/L
3 CW7-1 1,1-Dichloroethane 0 UG/L
4 CW7-1 1,1-Dichloroethylene 0 UG/L
5 CW7-1 1,1-Dichloropropene 0 UG/L
6 CW7-1 1,2,3-Trichlorobenzene 0 UG/L
... ... ... ... ...
50311 VOA2-2 Tetrachloroethylene 1.8 MG/KG
50312 VOA2-2 Toluene 1.2 MG/KG
50313 VOA2-2 Trichloroethylene 1.8 MG/KG
50314 VOA2-2 Vinyl Chloride 1.8 MG/KG
座標データ(座標):
Sample x y
0 CW7-1 320800.000 396500.000
1 CW7-2 320800.000 396500.000
2 CW7-3 320800.000 396500.000
3 FB06-17 0.000 0.000
4 FB06-18 0.000 0.000
5 FB06-19 0.000 0.000
6 FB07-08 0.000 0.000
... ... ... ...
453 TP21-1 318807.281 398547.485
454 TP21-2 318807.281 398547.485
455 TP24-1 318489.248 398544.797
456 VOA1-1 318500.582 398573.558
457 VOA1-2 318500.582 398573.558
458 VOA2-1 318536.337 398589.805
459 VOA2-2 318536.337 398589.805
各濃度のそれぞれのサンプルIDのすべての座標を含む2つの列を濃度データフレームに追加したいと思います。たとえば、濃度データの最初の6行には、すべてCW7-1のサンプルIDがあるため、x = 320800およびy = 396500の列があります。
Sample analParam Conc Units x y
0 CW7-1 1,1,1-Trichloroethane 0 UG/L 320800 396500
1 CW7-1 1,1,2,2-Tetrachloroethane 0 UG/L 320800 396500
2 CW7-1 1,1,2-Trichloroethane 0 UG/L 320800 396500
3 CW7-1 1,1-Dichloroethane 0 UG/L 320800 396500
4 CW7-1 1,1-Dichloroethylene 0 UG/L 320800 396500
5 CW7-1 1,1-Dichloropropene 0 UG/L 320800 396500
double forループを使用してみましたが、データポイントが非常に多いため、時間がかかりすぎます。
for index, row in conc.iterrows():
for cindex, crow in coord.iterrows():
if conc.iloc[index,0] == coord.iloc[cindex,0]:
conc.at[index,4] = coord.iloc[cindex,1]
conc.at[index,5] = coord.iloc[cindex,2]
適用機能を使用してみましたが、エラーが発生し続けます。この演出のために、私は例外TypeErrorが得た:呼び出し()は1〜2位置引数からかかりますが、3が与えられました。
def xcoord (i):
for index, row in coord.iterrows():
if i == coord.iloc[index,0] :
return coord.iloc(index,4)
conc['Sample'].apply(xcoord)
ありがとうウェン!
In[1]:
conc.merge(coord,on='Sample',how='left')
Out[1]:
Sample analParam Conc Units x y
0 CW7-1 1,1,1-Trichloroethane 0 UG/L 320800.000 396500.000
1 CW7-1 1,1,2,2-Tetrachloroethane 0 UG/L 320800.000 396500.000
2 CW7-1 1,1,2-Trichloroethane 0 UG/L 320800.000 396500.000
3 CW7-1 1,1-Dichloroethane 0 UG/L 320800.000 396500.000
4 CW7-1 1,1-Dichloroethylene 0 UG/L 320800.000 396500.000
5 CW7-1 1,1-Dichloropropene 0 UG/L 320800.000 396500.000
6 CW7-1 1,2,3-Trichlorobenzene 0 UG/L 320800.000 396500.000
... ... ... ... ... ... ...
50311 VOA2-2 Tetrachloroethylene 1.8 MG/KG 318536.337 398589.805
50312 VOA2-2 Toluene 1.2 MG/KG 318536.337 398589.805
50313 VOA2-2 trans-1,3-Dichloropropene 1.8 MG/KG 318536.337 398589.805
50314 VOA2-2 Trichloroethylene 1.8 MG/KG 318536.337 398589.805
50315 VOA2-2 Vinyl Chloride 1.8 MG/KG 318536.337 398589.805
50316 VOA2-2 Xylenes (Total) 2.6 MG/KG 318536.337 398589.805
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加