Python
excel 데이터 group by concatenate
ndlessrain
2023. 7. 9. 13:29
728x90
import pandas as pd
df = pd.read_excel("C:/jupyter_notebook/name_concatenate.xlsx")
df["name"] = df["name"].str.replace(pat=r'[^\w!()/]', repl=r' ', regex=True) // 특수문자 치환, 괄호와 슬래쉬 제외
df2 = df.groupby(['id'])['name'].apply('<br>'.join) // id로 group by 해서 합치는데 사이에 <br> 추가
df2.to_excel('test.xlsx')
728x90