|||
摘要:根据要求进行字符串的提取,并去重
导入分析所需的库
import pandas as pd
构造数据集
as1 = pd.DataFrame({'a':[1,2,3,4], 'b':['adwdea,asdw;swa,des','swa,dwad;asdw;swa','se;dw,asd;erf,de','de']})
编写分析函数
def trans(b): as1['c'] = b.str.split(";") c = as1['c'].tolist() for i in range(len(c)): for j in range(len(c[i])): c[i][j] = c[i][j].split(",")[0] return c trans(as1['b']) as1['d'] = as1['c'].apply(lambda x:set(x)).apply(lambda x:",".join(x)) as1
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-9-1 14:36
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社