1 回答
TA贡献1725条经验 获得超7个赞
你有没有尝试过
import pandas as pd
df = pd.DataFrame({'Interpret': ['Afrika Bambaataa And Family', 'Sha Hef', 'Sido', 'Sido'],
'Title': ['The Decade Of Darkness 1990-2000', 'Out The Mud', 'Ich Und Keine Maske', 'Ich Und Keine Maske'],
'Formats': ['CD, Album, RE', 'CD, Album', 'CD, Album', '2xLP, Album']})
# remove duplicate interprets and merge formats...
df1 = df.groupby('Interpret').agg(lambda x: ', '.join(x.unique())).reset_index()
# now to get rid of duplicate entries in 'Formats' column...
def drop_dupes(row):
l = row.split(', ')
return ', '.join(list(set(l)))
df1['Formats'] = df1['Formats'].apply(drop_dupes)
? 那给你
Out[40]:
Interpret ... Formats
0 Afrika Bambaataa And Family ... CD, RE, Album
1 Sha Hef ... CD, Album
2 Sido ... CD, Album, 2xLP
并且基本上是您为这个问题找到的答案的略微修改版本。
添加回答
举报