答案 0 :(得分:2)
尝试:
# Setup
df = pd.DataFrame({'col1':{0:89,1:53,2:97,3:106,4:115,5:56,6:55,7:105,8:71,9:70,10:110},'col2':{0:205,1:205,2:205,3:203,4:203,5:203,6:202,7:201,8:200,9:200,10:198}})
df_new = df.groupby('col2', sort=False)['col1'].apply(list).reset_index()
df_new['col2'] = df_new['col1'].str.len().astype(str) + '*' + df_new.pop('col2').astype(str)
print(df_new)
[出]
col1 col2
0 [89, 53, 97] 3*205
1 [106, 115, 56] 3*203
2 [55] 1*202
3 [105] 1*201
4 [71, 70] 2*200
5 [110] 1*198