質問編集履歴
2
修正
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -134,6 +134,7 @@
|
|
|
134
134
|
|
|
135
135
|
new_df = pd.DataFrame(minds,columns=['no','x', 'y','PARAM','URL','URL2'])
|
|
136
136
|
final_df= pd.concat([new_df,fai_df],sort=False)
|
|
137
|
+
final_df= final_df.drop_duplicates(subset='no')
|
|
137
138
|
return(final_df)
|
|
138
139
|
|
|
139
140
|
if __name__ == '__main__':
|
|
@@ -143,28 +144,22 @@
|
|
|
143
144
|
|
|
144
145
|
```
|
|
145
146
|
no x y PARAM URL
|
|
147
|
+
0 0 3142.5 1125 FAI17/SPCA C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result1.png
|
|
148
|
+
1 1 3452.5 1653 FAI18/SPCB C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result2.png
|
|
149
|
+
2 12 2318.5 3087 FAI2l/SPCE C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result17.png
|
|
150
|
+
3 4 1701.5 3615 FAI22/SPCF C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result10.png
|
|
151
|
+
4 5 3741.5 3493 FAI23/SPCG C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result9.png
|
|
152
|
+
5 6 4891.5 3825 FAI24/SPCH C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result18.png
|
|
153
|
+
6 7 4923.5 3108 FAI25/SPCI C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result13.png
|
|
154
|
+
7 11 1371.5 1048 FAI29/SPCJ C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result11.png
|
|
155
|
+
8 16 2035.5 1796 FAIL30/SPCK C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result12.png
|
|
156
|
+
9 3 3705.5 964 FAI20/SPCOo C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result14.png
|
|
157
|
+
10 13 2257.5 1769 FAI41/SPCQa C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result15.png
|
|
158
|
+
11 14 3167.5 2224 FAI42/SPCR C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result4.png
|
|
159
|
+
12 2 3386.5 1377 FAI19/SPCc C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result3.png
|
|
146
|
-
|
|
160
|
+
8 8 5516.5 3269 FAI26 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result6.png
|
|
147
|
-
1 1 3383.5 1089 FAI10 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result14.png
|
|
148
|
-
|
|
161
|
+
9 9 4850.5 3617 FAI27 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result5.png
|
|
149
|
-
3 3 4302.5 1050 FAI12 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result1.png
|
|
150
|
-
4 4 4013.5 1381 FAI13 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result2.png
|
|
151
|
-
5 5 4249.5 1463 FAI14 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result8.png
|
|
152
|
-
6 6 4734.5 1009 FAI15 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result4.png
|
|
153
|
-
7 7 4873.5 1980 FAI16 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result6.png
|
|
154
|
-
8 8 1600.5 923 FAI2 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result21.png
|
|
155
|
-
9 9 2311.5 591 FAI3 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result12.png
|
|
156
|
-
10 10 3171.5 2622 FAI31 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result11.png
|
|
157
|
-
11 11 3784.5 2546 FAI32 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result5.png
|
|
158
|
-
12 12 4226.5 2639 FAI33 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result16.png
|
|
159
|
-
|
|
162
|
+
10 10 4452.5 3113 FAI28 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result7.png
|
|
160
|
-
14 14 2730.5 2989 FAI35 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result20.png
|
|
161
|
-
15 15
|
|
163
|
+
15 15 2064.5 2153 FAI43 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result8.png
|
|
162
|
-
|
|
164
|
+
|
|
163
|
-
17 17 3061.5 1664 FAI45 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result23.png
|
|
164
|
-
18 18 4510.5 1152 FAI46 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result7.png
|
|
165
|
-
19 19 2248.5 1636 FAI5 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result13.png
|
|
166
|
-
20 20 2394.5 1664 FAI6 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result19.png
|
|
167
|
-
21 21 2778.5 1177 FAI7 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result10.png
|
|
168
|
-
22 22 2829.5 952 FAI8 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result17.png
|
|
169
|
-
23 23 2935.5 1055 FAI9g C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result15.png
|
|
170
165
|
```
|
1
解決
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
下記のようなPANDASのデータフレームに入っているデータがあります。
|
|
2
2
|
|
|
3
3
|
データ系列
|
|
4
|
-
・
|
|
4
|
+
・PARAM列に、SPC〇 もしくは、FAI〇 とう文字列のデータがある。
|
|
5
5
|
・SPC〇、FAI〇は、常に1対1対応の関係にある。
|
|
6
6
|
|
|
7
7
|
### 実施したい処理
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
```
|
|
43
|
-
Unnamed: 0 x y
|
|
43
|
+
Unnamed: 0 x y PARAM URL
|
|
44
44
|
15 15 3142.5 1039.0 SPCA C:\Users\mm05162\Documents\GitHub\opencv\OPENC...
|
|
45
45
|
18 18 3238.5 2224.0 SPCR C:\Users\mm05162\Documents\GitHub\opencv\OPENC...
|
|
46
46
|
19 19 1371.5 959.0 SPCJ C:\Users\mm05162\Documents\GitHub\opencv\OPENC...
|
|
@@ -94,4 +94,77 @@
|
|
|
94
94
|
28 4994.5 3108.0 SPCI C:\Users\mm05162\Documents\GitHub\opencv\OPENC...
|
|
95
95
|
29 2387.5 3087.0 SPCE C:\Users\mm05162\Documents\GitHub\opencv\OPENC...
|
|
96
96
|
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### 自己解決(案)
|
|
100
|
+
|
|
101
|
+
ひとまず動くものを作成する必要があり、下記のように作成しました。
|
|
102
|
+
FAI〇を番号で並べようとしていますが、文字列ソートなので、
|
|
103
|
+
|
|
104
|
+
FAI1 → FAI10 というふうになります。
|
|
105
|
+
|
|
106
|
+
これをFAI1,FAI2という、文字列+数字でソーティングするところが
|
|
107
|
+
まだ出来ていませんが、まず動いたので、これで本件は解決になりました。
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
import pandas as pd
|
|
112
|
+
import math
|
|
113
|
+
|
|
114
|
+
def distance(a,b,c,d):
|
|
115
|
+
return math.sqrt((a-c)**2+(b-d)**2)
|
|
116
|
+
|
|
117
|
+
def main(file):
|
|
118
|
+
df = pd.read_csv(file)
|
|
119
|
+
df=df.rename(columns={df.columns[0]: 'no'})
|
|
120
|
+
|
|
121
|
+
fai_df=df[df['PARAM'].str.contains('FAI')]
|
|
122
|
+
spc_df=df[df['PARAM'].str.contains('SPC')]
|
|
123
|
+
|
|
124
|
+
minds =[]
|
|
125
|
+
for j,spc in spc_df.iterrows():
|
|
126
|
+
mind = 9999999999
|
|
127
|
+
pair =[]
|
|
128
|
+
for i,fai in fai_df.iterrows():
|
|
129
|
+
dis = distance(fai['x'],fai['y'],spc['x'],spc['y'])
|
|
130
|
+
if dis < mind:
|
|
131
|
+
mind = dis
|
|
132
|
+
pair=[i,fai['x'],fai['y'],fai['PARAM']+"/"+spc['PARAM'],fai['URL'],spc['URL']]
|
|
133
|
+
minds.append(pair)
|
|
134
|
+
|
|
135
|
+
new_df = pd.DataFrame(minds,columns=['no','x', 'y','PARAM','URL','URL2'])
|
|
136
|
+
final_df= pd.concat([new_df,fai_df],sort=False)
|
|
137
|
+
return(final_df)
|
|
138
|
+
|
|
139
|
+
if __name__ == '__main__':
|
|
140
|
+
df= main(file)
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
no x y PARAM URL
|
|
146
|
+
0 0 2796.5 1402 FAI1 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result9.png
|
|
147
|
+
1 1 3383.5 1089 FAI10 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result14.png
|
|
148
|
+
2 2 3790.5 1697 FAI11 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result3.png
|
|
149
|
+
3 3 4302.5 1050 FAI12 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result1.png
|
|
150
|
+
4 4 4013.5 1381 FAI13 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result2.png
|
|
151
|
+
5 5 4249.5 1463 FAI14 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result8.png
|
|
152
|
+
6 6 4734.5 1009 FAI15 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result4.png
|
|
153
|
+
7 7 4873.5 1980 FAI16 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result6.png
|
|
154
|
+
8 8 1600.5 923 FAI2 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result21.png
|
|
155
|
+
9 9 2311.5 591 FAI3 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result12.png
|
|
156
|
+
10 10 3171.5 2622 FAI31 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result11.png
|
|
157
|
+
11 11 3784.5 2546 FAI32 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result5.png
|
|
158
|
+
12 12 4226.5 2639 FAI33 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result16.png
|
|
159
|
+
13 13 4179.5 3135 FAI34 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result24.png
|
|
160
|
+
14 14 2730.5 2989 FAI35 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result20.png
|
|
161
|
+
15 15 1831.5 1559 FAI4 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result18.png
|
|
162
|
+
16 16 2912.5 1664 FAI44 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result22.png
|
|
163
|
+
17 17 3061.5 1664 FAI45 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result23.png
|
|
164
|
+
18 18 4510.5 1152 FAI46 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result7.png
|
|
165
|
+
19 19 2248.5 1636 FAI5 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result13.png
|
|
166
|
+
20 20 2394.5 1664 FAI6 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result19.png
|
|
167
|
+
21 21 2778.5 1177 FAI7 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result10.png
|
|
168
|
+
22 22 2829.5 952 FAI8 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result17.png
|
|
169
|
+
23 23 2935.5 1055 FAI9g C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result15.png
|
|
97
170
|
```
|