回答編集履歴
2
Update
test
CHANGED
@@ -15,7 +15,8 @@
|
|
15
15
|
#
|
16
16
|
cols = ['スーパー', '公園', '小学校', '中学校', '警察署', '病院']
|
17
17
|
category= (
|
18
|
+
df.set_index('index')
|
18
|
-
|
19
|
+
.apply(lambda x:
|
19
20
|
x.str.extract(r'((?P<category>.+)).*?(?P<distance>\d+)m$', expand=True)
|
20
21
|
.pivot_table(columns='category', values='distance', aggfunc='min')
|
21
22
|
.stack(), axis=1)
|
1
Update
test
CHANGED
@@ -16,11 +16,10 @@
|
|
16
16
|
cols = ['スーパー', '公園', '小学校', '中学校', '警察署', '病院']
|
17
17
|
category= (
|
18
18
|
df.iloc[:, 1:].apply(lambda x:
|
19
|
-
x.str.extract(r'((?P<category>.+)).*?(?P<
|
19
|
+
x.str.extract(r'((?P<category>.+)).*?(?P<distance>\d+)m$', expand=True)
|
20
|
-
.pivot_table(columns='category', values='
|
20
|
+
.pivot_table(columns='category', values='distance', aggfunc='min')
|
21
21
|
.stack(), axis=1)
|
22
|
-
.droplevel(level=0, axis=1)[cols]
|
23
|
-
.reset_index().rename_axis(None, axis=1))
|
22
|
+
.droplevel(level=0, axis=1)[cols].reset_index().rename_axis(None, axis=1))
|
24
23
|
|
25
24
|
print(category.to_markdown(index=False))
|
26
25
|
```
|