回答編集履歴
3
また見直し
answer
CHANGED
@@ -11,4 +11,16 @@
|
|
11
11
|
# 1 10012 Rice 1500
|
12
12
|
# 4 10015 Egg 1000
|
13
13
|
# 5 10016 Tea 1000
|
14
|
+
```
|
15
|
+
|
16
|
+
---
|
17
|
+
|
18
|
+
こっちのほうがいいかも
|
19
|
+
|
20
|
+
```Python
|
21
|
+
is_ticket = df.loc[:, 'PName'].str.startswith('TicketNo-').to_numpy()
|
22
|
+
is_remove_pcode = df.loc[:, 'PCode'].to_numpy() == 10011
|
23
|
+
|
24
|
+
cond = np.r_[False, (is_ticket[:-1] & is_remove_pcode[1:]), False]
|
25
|
+
res = df.loc[~(cond[1:] | cond[:-1])]
|
14
26
|
```
|
2
抜けてた!
answer
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
is_ticket = df['PName'].str.startswith('TicketNo-').to_numpy()
|
3
3
|
is_remove_pcode = df['PCode'].to_numpy() == 10011
|
4
4
|
|
5
|
-
drop_index = np.all([is_ticket, np.concatenate((is_remove_pcode[1:], is_remove_pcode[-1:]))], 0)
|
5
|
+
drop_index = np.all([is_ticket, np.concatenate((is_remove_pcode[1:], is_remove_pcode[-1:]))], 0).nonzero()[0]
|
6
6
|
res = df.drop([*drop_index, *(drop_index+1)])
|
7
7
|
|
8
8
|
print(res)
|
1
to_numpy利用
answer
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
```Python
|
2
|
-
is_ticket = df['PName'].str.startswith('TicketNo-')
|
2
|
+
is_ticket = df['PName'].str.startswith('TicketNo-').to_numpy()
|
3
|
-
is_remove_pcode = df['PCode'] == 10011
|
3
|
+
is_remove_pcode = df['PCode'].to_numpy() == 10011
|
4
4
|
|
5
|
-
drop_index = np.all([is_ticket,
|
5
|
+
drop_index = np.all([is_ticket, np.concatenate((is_remove_pcode[1:], is_remove_pcode[-1:]))], 0)
|
6
|
-
res = df.drop([*drop_index, *drop_index+1])
|
6
|
+
res = df.drop([*drop_index, *(drop_index+1)])
|
7
7
|
|
8
8
|
print(res)
|
9
9
|
# PCode PName Price
|