我有一個熊貓數據框,其中一列是一個系列本身。例如:分組的熊貓列(這是一個系列本身)的合併系列
df.head()
Col1 Col2
1 ["name1","name2","name3"]
1 ["name3","name2","name4"]
2 ["name1","name2","name3"]
2 ["name1","name5","name6"]
我需要在Col1組中連接Col2。我想是這樣
Col1 Col2
1 ["name1","name2","name3","name4"]
2 ["name1","name2","name3","name5","name6"]
我試圖使用GROUPBY作爲
.agg({"Col2":lambda x: pd.Series.append(x)})
但是,這將引發錯誤,說需要兩個參數。我也嘗試在agg函數中使用sum。這種失敗並不會減少錯誤。
我該怎麼做?