pd.DataFrame c = ({ 'id': [ 'xx', 'xyy', 'zz', 'mm], the [' 10 ', 10', 11 ', np.nan] , 'b': [ '11', 12 ', 11', np.nan] c: [ '10', '12', '', np.nan] d: [ ' 10 ', 10', 10 ', np.nan], he [' 10 ',' 10 ',' 11 ',' ']}) c
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 controlled by row or by column