回答編集履歴
1
applyを使う方法を追加
test
CHANGED
@@ -35,3 +35,33 @@
|
|
35
35
|
3 4 abZ
|
36
36
|
|
37
37
|
```
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
applyを使うとこうです。
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
```python
|
46
|
+
|
47
|
+
>>> import pandas
|
48
|
+
|
49
|
+
>>> import numpy as np
|
50
|
+
|
51
|
+
>>> path = pd.DataFrame({'A':[1,2,3,4], 'path1': ['Abc', 'aBc', 'zzA', 'abZ']})
|
52
|
+
|
53
|
+
>>> path['path1'] = path['path1'].apply(lambda x: x if x[0] != 'A' else np.nan)
|
54
|
+
|
55
|
+
>>> print(path)
|
56
|
+
|
57
|
+
A path1
|
58
|
+
|
59
|
+
0 1 NaN
|
60
|
+
|
61
|
+
1 2 aBc
|
62
|
+
|
63
|
+
2 3 zzA
|
64
|
+
|
65
|
+
3 4 abZ
|
66
|
+
|
67
|
+
```
|