- 博客(3)
- 收藏
- 关注
原创 pandas ,一行拆分为多行
result=df.set_index(["姓名", "年龄"])["兴趣"].str.split(",", expand=True).stack().reset_index(drop=True,level=-1).reset_index().rename(columns={0:'兴趣'})'兴趣':['篮球,足球,羽毛球','高尔夫,唱歌','骑马']})df = pd.DataFrame({'姓名': ['小明','小红','小黑'],'年龄':['25','26','22'],
2023-11-15 15:14:59 143
原创 pandas 按照行合并数据
data_new['品牌']=data_new['品牌'].apply(lambda x:str(x).replace('[','').replace(']',''))data=pd.DataFrame({'id':[1,1,2,2],'品牌':['A','B','C','D']})data_new=data.groupby(['id'])['品牌'].apply(list).to_frame()
2023-10-09 10:26:09 87 1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人