回答編集履歴
1
edit
test
CHANGED
@@ -13,3 +13,61 @@
|
|
13
13
|
|
14
14
|
|
15
15
|
`apply`を組み合わせてみてはいかがでしょう。
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
---
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
雰囲気だけ。
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
```python
|
28
|
+
|
29
|
+
import pandas as pd
|
30
|
+
|
31
|
+
import numpy as np
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
df1 = pd.DataFrame({'Information1' : [19, 'game. tennis','Prof. HANA YAMADA', 'Canada.'],
|
36
|
+
|
37
|
+
'Information2' : ['books', 24, 'Shopping.','A. ELIZABETH JONES.'],
|
38
|
+
|
39
|
+
'Information3' : ['Mr. ADAMS', 'Italy', 'Japan', 23],
|
40
|
+
|
41
|
+
'Information4' : ['Australia', 'MARCO', 25, 'movies']},
|
42
|
+
|
43
|
+
index = {'Person1','Person2','Person3', 'Person4'}
|
44
|
+
|
45
|
+
)
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
import re
|
50
|
+
|
51
|
+
f = re.compile(r"\b[A-Z]+\b")
|
52
|
+
|
53
|
+
def ff(item):
|
54
|
+
|
55
|
+
ans = f.findall(item)
|
56
|
+
|
57
|
+
if len(ans) == 0:
|
58
|
+
|
59
|
+
return ''
|
60
|
+
|
61
|
+
else:
|
62
|
+
|
63
|
+
return ' '.join(ans)
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
tdf = df1.astype(str).applymap(ff)
|
68
|
+
|
69
|
+
tdf = tdf.apply(sorted, axis=1, reverse=True)
|
70
|
+
|
71
|
+
print(tdf)
|
72
|
+
|
73
|
+
```
|