[英]how to convert multiple rows into single row for same id using pandas
[英]how do I convert a n rows to a single row in pandas?
我正在嘗試將 pd.series 轉換為 pd.df 我有下一個 df:
COL1
0 a
1 b
2 c
3 d
4 e
5 f
. .
. .
n n
我需要像這樣轉換它:
COL1 COL2 COL3
0 a b c
1 d e f
. . . .
. . . .
n n n n
讓我們嘗試reshape
out = pd.DataFrame(df.COL1.values.reshape((-1,3)))
Out[243]:
0 1 2
0 a b c
1 d e f
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.