Pandas 값 인접한 것끼리 그룹 지정하기

Jmnote (토론 | 기여)님의 2021년 10월 10일 (일) 15:31 판 (새 문서: ==개요== ;Pandas 인접한 것끼리 그룹 지정하기 ==예시== <syntaxhighlight lang='python' notebook=1> import pandas as pd import numpy as np df = pd.DataFrame({ 'name':...)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요

Pandas 인접한 것끼리 그룹 지정하기

2 예시

import pandas as pd
import numpy as np

df = pd.DataFrame({
  'name': ['A','B','C','D','E','F','G','H','I','J','K','L','M'],
  'num':  [  1,  2,  3,  4,  5,  7,  8,  9, 10, 13, 14, 15, 16],
})
df
df['group'] = 'Group'+(df.num != df.num.shift()+1).cumsum().astype('string')
df

3 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}