質問編集履歴

2

修正

2019/10/08 03:50

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -270,6 +270,8 @@
270
270
 
271
271
  final_df= pd.concat([new_df,fai_df],sort=False)
272
272
 
273
+ final_df= final_df.drop_duplicates(subset='no')
274
+
273
275
  return(final_df)
274
276
 
275
277
 
@@ -288,52 +290,40 @@
288
290
 
289
291
  no x y PARAM URL
290
292
 
293
+ 0 0 3142.5 1125 FAI17/SPCA C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result1.png
294
+
295
+ 1 1 3452.5 1653 FAI18/SPCB C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result2.png
296
+
297
+ 2 12 2318.5 3087 FAI2l/SPCE C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result17.png
298
+
299
+ 3 4 1701.5 3615 FAI22/SPCF C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result10.png
300
+
301
+ 4 5 3741.5 3493 FAI23/SPCG C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result9.png
302
+
303
+ 5 6 4891.5 3825 FAI24/SPCH C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result18.png
304
+
305
+ 6 7 4923.5 3108 FAI25/SPCI C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result13.png
306
+
307
+ 7 11 1371.5 1048 FAI29/SPCJ C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result11.png
308
+
309
+ 8 16 2035.5 1796 FAIL30/SPCK C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result12.png
310
+
311
+ 9 3 3705.5 964 FAI20/SPCOo C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result14.png
312
+
313
+ 10 13 2257.5 1769 FAI41/SPCQa C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result15.png
314
+
315
+ 11 14 3167.5 2224 FAI42/SPCR C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result4.png
316
+
317
+ 12 2 3386.5 1377 FAI19/SPCc C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result3.png
318
+
291
- 0 0 2796.5 1402 FAI1 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result9.png
319
+ 8 8 5516.5 3269 FAI26 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result6.png
292
-
293
- 1 1 3383.5 1089 FAI10 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result14.png
320
+
294
-
295
- 2 2 3790.5 1697 FAI11 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result3.png
321
+ 9 9 4850.5 3617 FAI27 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result5.png
296
-
297
- 3 3 4302.5 1050 FAI12 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result1.png
322
+
298
-
299
- 4 4 4013.5 1381 FAI13 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result2.png
300
-
301
- 5 5 4249.5 1463 FAI14 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result8.png
302
-
303
- 6 6 4734.5 1009 FAI15 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result4.png
304
-
305
- 7 7 4873.5 1980 FAI16 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result6.png
306
-
307
- 8 8 1600.5 923 FAI2 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result21.png
308
-
309
- 9 9 2311.5 591 FAI3 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result12.png
310
-
311
- 10 10 3171.5 2622 FAI31 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result11.png
312
-
313
- 11 11 3784.5 2546 FAI32 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result5.png
314
-
315
- 12 12 4226.5 2639 FAI33 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result16.png
316
-
317
- 13 13 4179.5 3135 FAI34 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result24.png
323
+ 10 10 4452.5 3113 FAI28 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result7.png
318
-
319
- 14 14 2730.5 2989 FAI35 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result20.png
324
+
320
-
321
- 15 15 1831.5 1559 FAI4 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result18.png
325
+ 15 15 2064.5 2153 FAI43 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result8.png
322
-
323
- 16 16 2912.5 1664 FAI44 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result22.png
326
+
324
-
325
- 17 17 3061.5 1664 FAI45 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result23.png
327
+
326
-
327
- 18 18 4510.5 1152 FAI46 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result7.png
328
+
328
-
329
- 19 19 2248.5 1636 FAI5 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result13.png
330
-
331
- 20 20 2394.5 1664 FAI6 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result19.png
332
-
333
- 21 21 2778.5 1177 FAI7 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result10.png
334
-
335
- 22 22 2829.5 952 FAI8 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result17.png
336
-
337
- 23 23 2935.5 1055 FAI9g C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result15.png
338
-
339
- ```
329
+ ```

1

解決

2019/10/08 03:50

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  データ系列
6
6
 
7
- FAI列に、SPC〇 もしくは、FAI〇 とう文字列のデータがある。
7
+ PARAM列に、SPC〇 もしくは、FAI〇 とう文字列のデータがある。
8
8
 
9
9
  ・SPC〇、FAI〇は、常に1対1対応の関係にある。
10
10
 
@@ -82,7 +82,7 @@
82
82
 
83
83
  ```
84
84
 
85
- Unnamed: 0 x y FAI URL
85
+ Unnamed: 0 x y PARAM URL
86
86
 
87
87
  15 15 3142.5 1039.0 SPCA C:\Users\mm05162\Documents\GitHub\opencv\OPENC...
88
88
 
@@ -191,3 +191,149 @@
191
191
 
192
192
 
193
193
  ```
194
+
195
+
196
+
197
+ ### 自己解決(案)
198
+
199
+
200
+
201
+ ひとまず動くものを作成する必要があり、下記のように作成しました。
202
+
203
+ FAI〇を番号で並べようとしていますが、文字列ソートなので、
204
+
205
+
206
+
207
+ FAI1 → FAI10 というふうになります。
208
+
209
+
210
+
211
+ これをFAI1,FAI2という、文字列+数字でソーティングするところが
212
+
213
+ まだ出来ていませんが、まず動いたので、これで本件は解決になりました。
214
+
215
+
216
+
217
+
218
+
219
+ ```python
220
+
221
+ import pandas as pd
222
+
223
+ import math
224
+
225
+
226
+
227
+ def distance(a,b,c,d):
228
+
229
+ return math.sqrt((a-c)**2+(b-d)**2)
230
+
231
+
232
+
233
+ def main(file):
234
+
235
+ df = pd.read_csv(file)
236
+
237
+ df=df.rename(columns={df.columns[0]: 'no'})
238
+
239
+
240
+
241
+ fai_df=df[df['PARAM'].str.contains('FAI')]
242
+
243
+ spc_df=df[df['PARAM'].str.contains('SPC')]
244
+
245
+
246
+
247
+ minds =[]
248
+
249
+ for j,spc in spc_df.iterrows():
250
+
251
+ mind = 9999999999
252
+
253
+ pair =[]
254
+
255
+ for i,fai in fai_df.iterrows():
256
+
257
+ dis = distance(fai['x'],fai['y'],spc['x'],spc['y'])
258
+
259
+ if dis < mind:
260
+
261
+ mind = dis
262
+
263
+ pair=[i,fai['x'],fai['y'],fai['PARAM']+"/"+spc['PARAM'],fai['URL'],spc['URL']]
264
+
265
+ minds.append(pair)
266
+
267
+
268
+
269
+ new_df = pd.DataFrame(minds,columns=['no','x', 'y','PARAM','URL','URL2'])
270
+
271
+ final_df= pd.concat([new_df,fai_df],sort=False)
272
+
273
+ return(final_df)
274
+
275
+
276
+
277
+ if __name__ == '__main__':
278
+
279
+ df= main(file)
280
+
281
+
282
+
283
+ ```
284
+
285
+
286
+
287
+ ```
288
+
289
+ no x y PARAM URL
290
+
291
+ 0 0 2796.5 1402 FAI1 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result9.png
292
+
293
+ 1 1 3383.5 1089 FAI10 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result14.png
294
+
295
+ 2 2 3790.5 1697 FAI11 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result3.png
296
+
297
+ 3 3 4302.5 1050 FAI12 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result1.png
298
+
299
+ 4 4 4013.5 1381 FAI13 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result2.png
300
+
301
+ 5 5 4249.5 1463 FAI14 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result8.png
302
+
303
+ 6 6 4734.5 1009 FAI15 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result4.png
304
+
305
+ 7 7 4873.5 1980 FAI16 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result6.png
306
+
307
+ 8 8 1600.5 923 FAI2 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result21.png
308
+
309
+ 9 9 2311.5 591 FAI3 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result12.png
310
+
311
+ 10 10 3171.5 2622 FAI31 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result11.png
312
+
313
+ 11 11 3784.5 2546 FAI32 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result5.png
314
+
315
+ 12 12 4226.5 2639 FAI33 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result16.png
316
+
317
+ 13 13 4179.5 3135 FAI34 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result24.png
318
+
319
+ 14 14 2730.5 2989 FAI35 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result20.png
320
+
321
+ 15 15 1831.5 1559 FAI4 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result18.png
322
+
323
+ 16 16 2912.5 1664 FAI44 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result22.png
324
+
325
+ 17 17 3061.5 1664 FAI45 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result23.png
326
+
327
+ 18 18 4510.5 1152 FAI46 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result7.png
328
+
329
+ 19 19 2248.5 1636 FAI5 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result13.png
330
+
331
+ 20 20 2394.5 1664 FAI6 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result19.png
332
+
333
+ 21 21 2778.5 1177 FAI7 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result10.png
334
+
335
+ 22 22 2829.5 952 FAI8 C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result17.png
336
+
337
+ 23 23 2935.5 1055 FAI9g C:\Users\mm05162\Documents\GitHub\opencv\OPENCV_TESTING\result15.png
338
+
339
+ ```