回答編集履歴

2

Update

2022/03/09 15:55

投稿

melian
melian

スコア19825

test CHANGED
@@ -15,7 +15,8 @@
15
15
  #
16
16
  cols = ['スーパー', '公園', '小学校', '中学校', '警察署', '病院']
17
17
  category= (
18
+ df.set_index('index')
18
- df.iloc[:, 1:].apply(lambda x:
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

2022/03/09 15:47

投稿

melian
melian

スコア19825

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<price>\d+)m$', expand=True)
19
+ x.str.extract(r'((?P<category>.+)).*?(?P<distance>\d+)m$', expand=True)
20
- .pivot_table(columns='category', values='price', aggfunc='min')
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
  ```