Pandas 피벗테이블을 ndarray로 변환

1 개요[ | ]

Pandas 피벗테이블을 행렬로 변환
import pandas as pd
import numpy as np
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],
'product_id': [1,2,3,4,5,1,2,3,4,1,2,4,5,6],
'quantity': [1,1,2,10,5,4,10,3,1,2,1,1,1,1]
})
df
table = df.pivot_table(values='quantity', index='product_id', columns='user_id', fill_value=0)
table
table.to_numpy()

2 같이 보기[ | ]

3 참고[ | ]

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