标签:taf dict turn 次数 sha har csharp ret img
aa = pd.DataFrame({‘id‘:[‘xx‘,‘yy‘,‘zz‘,‘mm‘], ‘a‘:[‘10‘,‘10‘,‘11‘,np.nan],‘b‘:[‘11‘,‘12‘,‘11‘,np.nan],‘c‘:[‘10‘,‘12‘,‘‘,np.nan],‘d‘:[‘10‘,‘10‘,‘10‘,np.nan],‘e‘:[‘10‘,‘10‘,‘11‘,‘‘]}) aa
def map_func1(x): if (x[‘a‘] == x[‘b‘] == x[‘c‘] == x[‘d‘] == ‘‘): return ‘www‘ else: li = list(x[[‘a‘,‘b‘,‘c‘,‘d‘]]) print(li) set1 = set(li) dict1 = {} for item in set1: dict1.update({item:li.count(item)}) print(dict1) return max(dict1,key=dict1.get)
aa[‘xinlai‘] = aa.apply(map_func1,axis=1) #axis控制按行还是按列
标签:taf dict turn 次数 sha har csharp ret img
原文地址:https://www.cnblogs.com/xiaodongsuibi/p/12163235.html