Strange needs breed strange skills, and skills thrive with strange needs.

Today, a colleague asked for help to merge a document, but she felt that it would not work to merge the same content. Probably, all business products and hardware types corresponding to an agent should be displayed in one cell, and displayed in a branch.
After messing around with pivot tables and merging the same content, I started fiddling with the code.
The final result, I think, is the same as what my colleagues want, and the details need to be confirmed.
Paste code:
import pandas as pddf=pd.read_clipboard()dfc=pd.DataFrame(columns=df.columns)for i in range(len(df.代理商编号.unique())):        dfc.loc[i,'代理商编号']=df.代理商编号.unique()[i]    dfc.loc[i,'代理商名称']=df[df.代理商编号==df.代理商编号.unique()[i]].代理商名称.unique()[0]    dfc.loc[i,'业务产品']=str(list(df[df.代理商编号==df.代理商编号.unique()[i]].业务产品.unique())).replace("[",'').replace("]","").replace('"','').replace(',','\n')    dfc.loc[i,'硬件产品']=str(list(df[df.代理商编号==df.代理商编号.unique()[i]].硬件产品.unique())).replace("[",'').replace("]","").replace('"','').replace(',','\n')
dfc.to_excel(r'E:\工作计划\周例会数据分享\2022.08.28\测试.xlsx')
The finishing work that follows is probably to replace the extra single quotes with empty ones, and to set them to automatic line wrapping.
Get off work!