Pandas 그룹 내 건수 붙이기

1 개요[ | ]

Pandas 그룹 내 건수 붙이기
import pandas as pd
df = pd.DataFrame({
'id': [1,2,3,4,5,6,7,8,9,10,11,12,13,14],
'user_id': [1,1,1,1,1,2,2,2,2,3,3,3,3,3],
'action_type': ['login','logout','login','move','logout','login','move','move','logout','login','logout','login','move','logout'],
})
df
temp = pd.DataFrame(df.groupby(['user_id']).action_type.count())
temp.reset_index(inplace=True)
temp.rename(columns={'action_type':'action_count'},inplace=True)
df = pd.merge(df, temp, how='left', on='user_id')
df

2 같이 보기[ | ]

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