回答編集履歴
2
実行例変更
test
CHANGED
@@ -12,11 +12,21 @@
|
|
12
12
|
|
13
13
|
return [item == value for item in self]
|
14
14
|
|
15
|
+
def __setitem__(self, where, value):
|
16
|
+
|
17
|
+
for i, replace in enumerate(where):
|
18
|
+
|
19
|
+
replace and super().__setitem__(i, value)
|
20
|
+
|
15
21
|
|
16
22
|
|
17
23
|
train = Sample(['male', 'female', 'female', 'male', 'female'])
|
18
24
|
|
19
25
|
print(train == 'male')
|
26
|
+
|
27
|
+
train[train == 'male'] = 0
|
28
|
+
|
29
|
+
print(train)
|
20
30
|
|
21
31
|
```
|
22
32
|
|
@@ -28,4 +38,6 @@
|
|
28
38
|
|
29
39
|
[True, False, False, True, False]
|
30
40
|
|
41
|
+
[0, 'female', 'female', 0, 'female']
|
42
|
+
|
31
43
|
```
|
1
実装例追記
test
CHANGED
@@ -1 +1,31 @@
|
|
1
1
|
Pandas や numpy 特有ですけど、Pythonの機能で作り出すことができますよ。
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
実装例
|
6
|
+
|
7
|
+
```python
|
8
|
+
|
9
|
+
class Sample(list):
|
10
|
+
|
11
|
+
def __eq__(self, value):
|
12
|
+
|
13
|
+
return [item == value for item in self]
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
train = Sample(['male', 'female', 'female', 'male', 'female'])
|
18
|
+
|
19
|
+
print(train == 'male')
|
20
|
+
|
21
|
+
```
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
実行結果:
|
26
|
+
|
27
|
+
```python
|
28
|
+
|
29
|
+
[True, False, False, True, False]
|
30
|
+
|
31
|
+
```
|