回答編集履歴

3

また見直し

2019/12/24 07:47

投稿

kirara0048
kirara0048

スコア1399

test CHANGED
@@ -25,3 +25,27 @@
25
25
  # 5 10016 Tea 1000
26
26
 
27
27
  ```
28
+
29
+
30
+
31
+ ---
32
+
33
+
34
+
35
+ こっちのほうがいいかも
36
+
37
+
38
+
39
+ ```Python
40
+
41
+ is_ticket = df.loc[:, 'PName'].str.startswith('TicketNo-').to_numpy()
42
+
43
+ is_remove_pcode = df.loc[:, 'PCode'].to_numpy() == 10011
44
+
45
+
46
+
47
+ cond = np.r_[False, (is_ticket[:-1] & is_remove_pcode[1:]), False]
48
+
49
+ res = df.loc[~(cond[1:] | cond[:-1])]
50
+
51
+ ```

2

抜けてた!

2019/12/24 07:47

投稿

kirara0048
kirara0048

スコア1399

test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
 
8
8
 
9
- drop_index = np.all([is_ticket, np.concatenate((is_remove_pcode[1:], is_remove_pcode[-1:]))], 0)
9
+ drop_index = np.all([is_ticket, np.concatenate((is_remove_pcode[1:], is_remove_pcode[-1:]))], 0).nonzero()[0]
10
10
 
11
11
  res = df.drop([*drop_index, *(drop_index+1)])
12
12
 

1

to_numpy利用

2019/12/24 04:20

投稿

kirara0048
kirara0048

スコア1399

test CHANGED
@@ -1,14 +1,14 @@
1
1
  ```Python
2
2
 
3
- is_ticket = df['PName'].str.startswith('TicketNo-')
3
+ is_ticket = df['PName'].str.startswith('TicketNo-').to_numpy()
4
4
 
5
- is_remove_pcode = df['PCode'] == 10011
5
+ is_remove_pcode = df['PCode'].to_numpy() == 10011
6
6
 
7
7
 
8
8
 
9
- drop_index = np.all([is_ticket, is_remove_pcode.shift(-1)], 0).nonzero()[0]
9
+ drop_index = np.all([is_ticket, np.concatenate((is_remove_pcode[1:], is_remove_pcode[-1:]))], 0)
10
10
 
11
- res = df.drop([*drop_index, *drop_index+1])
11
+ res = df.drop([*drop_index, *(drop_index+1)])
12
12
 
13
13
 
14
14